Skip to content

feat(core): agent orchestration & context compression optimization#384

Merged
bobleer merged 1 commit intoGCWing:mainfrom
bobleer:feat/agent-orchestration-optimization
Apr 11, 2026
Merged

feat(core): agent orchestration & context compression optimization#384
bobleer merged 1 commit intoGCWing:mainfrom
bobleer:feat/agent-orchestration-optimization

Conversation

@bobleer
Copy link
Copy Markdown
Collaborator

@bobleer bobleer commented Apr 11, 2026

Summary

Multi-layered improvements to agent stability and efficiency, referencing Claude Code's architecture patterns for context compression and tool orchestration.

Tool Execution Fault Tolerance & Mixed Scheduling

  • execute_tools fault tolerance: Convert execute_tools ? to match in round_executor — on pipeline-level failure, generate is_error: true error results for every tool_call instead of aborting the entire round
  • get_task None fallback: When get_task returns None in tool_pipeline, use task_id as fallback to generate error results, ensuring tool_call/tool_result count always matches
  • Partitioned mixed scheduling: Replace all-parallel/all-serial tool execution with continuous concurrency-safety partitioning — safe tools run in parallel batches, non-safe tools run serially, batches execute in order to preserve write-after-read dependencies

Multi-layered Context Compression

  • L0 Microcompact: Lightweight pre-compression that runs before full compression, replacing old compactable tool results (Read/Bash/Grep/Glob and 8 others) with placeholders while keeping the 8 most recent intact (includes 4 unit tests)
  • L2 Emergency truncation: After all compression layers, if tokens still exceed context_window, drop oldest API rounds from context head until tokens fit
  • Compression circuit breaker: Skip full compression after 3 consecutive failures (microcompact + emergency truncation always run as fallback)
  • Unified context_window: Both execution_engine and coordinator manual compaction now use min(model_capability, session_config)

Resource Cleanup

  • Synchronously delete SessionContextStore in-memory data when idle sessions are evicted, preventing memory leaks

Changes

File Change
round_executor.rs execute_tools ?match fault tolerance
tool_pipeline.rs get_task fallback + partitioned mixed scheduling
microcompact.rs New Microcompact layer (with tests)
execution_engine.rs Microcompact integration + emergency truncation + circuit breaker + context_window unification
coordinator.rs Manual compaction context_window unification
session_manager.rs Eviction cleanup for context_store
message.rs Make estimate_tokens pub
compression/mod.rs Export microcompact module

Test plan

  • cargo check — zero errors, zero warnings
  • cargo test -p bitfun-core — all 202 tests pass (including 4 new microcompact tests)
  • Manual test: long conversation scenario to verify microcompact clearing effect
  • Manual test: mixed tool calls (concurrent + serial) to verify partitioned scheduling
  • Manual test: compression failure scenario to verify circuit breaker + emergency truncation fallback

Multi-layered improvements to agent stability and efficiency, referencing
Claude Code's architecture patterns:

Tool execution:
- round_executor: convert execute_tools `?` to `match`, generate per-tool
  error results on pipeline failure instead of aborting the round
- tool_pipeline: fallback to task_id when get_task returns None, ensuring
  tool_call/tool_result count always matches
- tool_pipeline: partitioned mixed scheduling — consecutive concurrency-safe
  tools run in parallel batches, non-safe tools run serially, preserving
  write-after-read ordering

Context compression:
- Add Microcompact layer (L0): proactively clear old compactable tool results
  (Read/Bash/Grep/Glob/etc.) before full compression, freeing significant
  tokens while preserving tool call structure
- Add emergency truncation (L2): drop oldest API rounds from context head
  when tokens still exceed context_window after all compression layers
- Add compression circuit breaker: skip full compression after 3 consecutive
  failures (microcompact + emergency truncation always run)
- Unify context_window source: use min(model_capability, session_config) in
  both execution_engine and coordinator manual compaction

Resource cleanup:
- Session eviction cleanup: delete SessionContextStore data when idle
  sessions are evicted from memory
@bobleer bobleer merged commit 59f8a49 into GCWing:main Apr 11, 2026
4 checks passed
@bobleer bobleer deleted the feat/agent-orchestration-optimization branch April 15, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant