Repository navigation
feat(harness): introduce async tool and notification support. - #1802
Conversation
…nce isolation scope handling
…scribe capabilities
…scribe capabilities
There was a problem hiding this comment.
Pull request overview
This PR introduces RC4 harness/runtime enhancements centered around async execution (tools + subagents), inbox-based hint delivery, deterministic session wakeups, and broader formatting/model support (notably HintBlock propagation and model context window awareness).
Changes:
- Add workspace-backed
MessageBus+AsyncToolRegistry, withInboxMiddlewareinjection of inbox/stale async results and aWakeupDispatcherto re-trigger idle sessions. - Improve async execution flows: tool offloading (
AsyncToolMiddleware), subagent task adoption on timeout (AdoptedTaskRunSpec), and task completion callbacks to push results + enqueue wakeups. - Extend core APIs and formatting/model plumbing: plain-text
call(...)overloads, structured-output robustness,HintBlocksupport across formatters, and dynamic compaction thresholds based on model context windows.
Reviewed changes
Copilot reviewed 92 out of 93 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/_static/custom.css | Adds styling for an AI context menu split-pill UI element in docs. |
| docs/_config.yml | Registers ai-context-menu.js in the Sphinx HTML build. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/subagent/task/AdoptedTaskRunSpecTest.java | New tests validating adopted async task tracking and persistence. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/middleware/InboxMiddlewareTest.java | New tests for inbox draining and hint injection into agent context. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/middleware/AsyncToolMiddlewareTest.java | New tests for tool offload behavior and background result delivery. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/gateway/WakeupDispatcherTest.java | New tests validating wakeup dispatch behavior for idle/running/unknown sessions. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/gateway/SessionIdUtilsTest.java | Tests for deterministic 12-hex session hashing. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/gateway/HarnessGatewaySessionIdTest.java | Tests ensuring deterministic gateway session IDs across instances. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/filesystem/LocalFilesystemModeTest.java | Adds tests ensuring namespace prefixing doesn’t corrupt absolute paths. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/example/support/InMemorySandbox.java | Improves cross-platform shell execution (Windows vs Unix). |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/bus/WorkspaceMessageBusTest.java | New tests for filesystem-backed message bus queue/log helpers. |
| agentscope-harness/src/test/java/io/agentscope/harness/agent/bus/WorkspaceAsyncToolRegistryTest.java | New tests for filesystem-backed async tool registry stale detection & recovery. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/WaitAsyncResultsTool.java | Adds a tool to block/poll for async results in a session inbox. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/MemorySaveTool.java | Adds a dedicated tool to append memories to MEMORY.md + daily ledger. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/task/WorkspaceTaskRepository.java | Adds adopted-future support and completion callbacks for background tasks. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/task/TaskRunSpec.java | Introduces AdoptedTaskRunSpec for already-running futures. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/WorkspaceContextMiddleware.java | Updates system prompt guidance to use memory_save tool instead of file edits. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/SubagentsMiddleware.java | Adds timeout-promotion guidance + wiring to push task results via message bus. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/MemoryMaintenanceMiddleware.java | Runs maintenance asynchronously on bounded elastic scheduler. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/MemoryFlushMiddleware.java | Runs flush asynchronously with bounded elastic scheduling and error logging. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/InboxMiddleware.java | New middleware to drain inbox + stale async tool records into context as HintBlocks. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/DynamicSubagentsMiddleware.java | Exposes task repository accessor for integration/wiring. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/CompactionMiddleware.java | Adds dynamic compaction trigger/keep computation using model context window size. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/AsyncToolMiddleware.java | New middleware to offload long-running tools and deliver results via inbox + wakeup. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/memory/compaction/ConversationCompactor.java | Adds non-LLM aggregate tool-result pruning before summarization. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/IsolationScope.java | Adds conversion to a NamespaceFactory based on isolation scope. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgentBuilderSupport.java | Ensures disable flags propagate correctly to subagent builders. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/gateway/WakeupDispatcher.java | New dispatcher that drains wakeup queue and triggers idle-session runs. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/gateway/SessionTurnGate.java | Adds isRunning(...) to detect in-progress turns for wakeup suppression. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/gateway/SessionIdUtils.java | New deterministic hash helper for stable, filename-safe session IDs. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/gateway/HarnessGateway.java | Implements wakeup target, deterministic session IDs, and session event publishing. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/spec/LocalFilesystemSpec.java | Adds IsolationScope configuration for local filesystem namespacing behavior. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/remote/RemoteFilesystem.java | Normalizes store item keys to ensure leading slash consistency. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystemWithShell.java | Adds Windows-compatible command invocation for execute operations. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/filesystem/local/LocalFilesystem.java | Prevents namespace prefixing of absolute paths (but needs Windows absolute handling). |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/DistributedStore.java | Adds optional MessageBus + AsyncToolRegistry to distributed store abstraction. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/WorkspaceMessageBus.java | New filesystem-backed implementation of MessageBus. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/WorkspaceAsyncToolRegistry.java | New filesystem-backed implementation of AsyncToolRegistry. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/MessageBus.java | New reactive bus abstraction with queue/log/pubsub and domain helpers (inbox/wakeup/events). |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/BusEntry.java | Defines a transport entry wrapper (entryId + payload). |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/AsyncToolRegistry.java | New registry interface for tracking background tool executions across crashes. |
| agentscope-harness/src/main/java/io/agentscope/harness/agent/bus/AsyncToolRecord.java | Defines persisted async tool execution record schema. |
| agentscope-extensions/agentscope-extensions-oss/src/test/java/io/agentscope/extensions/oss/OssBaseStoreTest.java | Adds tests ensuring leading slashes are stripped for OSS object keys. |
| agentscope-extensions/agentscope-extensions-oss/src/main/java/io/agentscope/extensions/oss/OssBaseStore.java | Strips leading slashes for data/version object key construction. |
| agentscope-examples/documentation/src/main/resources/skills/data-analysis/SKILL.md | Adds a new example skill definition for data analysis. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/tool/ToolGroupExample.java | Enables AgentTraceMiddleware in example. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/tool/ToolCallingWithConverterExample.java | Enables AgentTraceMiddleware in example. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/tool/ToolCallingExample.java | Updates example to add tracing middleware and use call() instead of manual streaming prints. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/tool/RoutingByToolCallsExample.java | Enables AgentTraceMiddleware in example. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/tool/PermissionContextExample.java | Clarifies permission rule evaluation order and marks read tool as readOnly. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/structuredoutput/StructuredOutputFallbackExample.java | New example demonstrating structured output fallback via generate_response. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/skill/SkillWithToolGroupExample.java | Updates skill path/name and adds trace middleware; improves prompts. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/skill/GitSkillRepositoryExample.java | New example demonstrating loading skills from a remote Git repository. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/skill/AgentSkillExample.java | Enables AgentTraceMiddleware in example. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/quickstart/UserIsolatedMultiTurnsExample.java | Updates example to use an explicit in-memory state store. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/subagent/SubagentStreamingExample.java | Improves streaming output formatting and adds persistent session/state store usage. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/subagent/SubagentSendDirectlyExample.java | Adds state store and expands example prompt. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/planmode/PlanModeAutoExample.java | Removes state-store usage to prevent cross-run leakage for plan mode. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/channel/ChannelSendExample.java | Adds state store and a delay to allow async processing before exit. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/async/AsyncWaitModeExample.java | New example showing “wait within call()” mode via wait_async_results. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/async/AsyncToolExample.java | New example demonstrating async tool offloading via inbox results. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/harness/async/AsyncSubagentExample.java | New example demonstrating async subagent completion via inbox + wakeup dispatcher. |
| agentscope-examples/documentation/src/main/java/io/agentscope/examples/documentation2/context/RuntimeContextExample.java | Updates example to fetch agent state via runtime context. |
| agentscope-examples/documentation/pom.xml | Adds dependency for the Git-based skill repository extension. |
| agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentStructuredOutputTest.java | Adds regression test for structured output when hooks null out reasoning message. |
| agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java | Adds plain-text call/stream overloads, improves runtime context merge, and hardens structured-output paths. |
| agentscope-core/src/main/java/io/agentscope/core/model/OpenAIChatModel.java | Adds builder override + inference for context window size. |
| agentscope-core/src/main/java/io/agentscope/core/model/OllamaChatModel.java | Adds builder override for context window size. |
| agentscope-core/src/main/java/io/agentscope/core/model/ModelContextWindows.java | New lookup table for known model context window sizes. |
| agentscope-core/src/main/java/io/agentscope/core/model/Model.java | Adds getContextWindowSize() API used by compaction logic. |
| agentscope-core/src/main/java/io/agentscope/core/model/GeminiChatModel.java | Adds builder override + inference for context window size. |
| agentscope-core/src/main/java/io/agentscope/core/model/DashScopeChatModel.java | Adds builder override + inference for context window size. |
| agentscope-core/src/main/java/io/agentscope/core/model/ChatModelBase.java | Stores/returns context window size for chat model implementations. |
| agentscope-core/src/main/java/io/agentscope/core/model/AnthropicChatModel.java | Adds builder override + inference for context window size. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIMessageConverter.java | Treats HintBlock as text content when formatting for OpenAI. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIConversationMerger.java | Merges HintBlock content into aggregated OpenAI conversation text. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/ollama/OllamaMessageConverter.java | Includes HintBlock in text extraction for Ollama requests. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/ollama/OllamaConversationMerger.java | Merges HintBlock content into aggregated Ollama conversation text. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/gemini/GeminiMessageConverter.java | Formats HintBlock as text parts for Gemini requests. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/gemini/GeminiConversationMerger.java | Merges HintBlock into Gemini conversation aggregation. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/dashscope/DashScopeMessageConverter.java | Formats HintBlock as text and includes it in text extraction. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/dashscope/DashScopeConversationMerger.java | Merges HintBlock into DashScope conversation aggregation. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/anthropic/AnthropicMessageConverter.java | Converts HintBlock to text blocks for Anthropic payloads. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/anthropic/AnthropicConversationMerger.java | Merges HintBlock into Anthropic conversation aggregation. |
| agentscope-core/src/main/java/io/agentscope/core/formatter/AbstractBaseFormatter.java | Includes HintBlock in shared text extraction logic. |
| agentscope-core/src/main/java/io/agentscope/core/agent/RuntimeContext.java | Allows type-safe retrieval for values stored in stringAttributes. |
| agentscope-core/src/main/java/io/agentscope/core/agent/CallableAgent.java | Adds plain-text call(...) overloads to callable agent API. |
| .gitignore | Ignores .omc/ directory. |
| int effectiveTrigger; | ||
| if (configTrigger == 0) { | ||
| if (contextWindow > 0) { | ||
| effectiveTrigger = contextWindow - config.getReserved(); |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR introduces a comprehensive async tool and notification framework for agentscope-harness, alongside core improvements: HintBlock propagation through all formatters, String/Message convenience overloads on CallableAgent, userId/sessionId preservation in merged RuntimeContext, contextWindowSize builder support on chat models, and deterministic session IDs. The design is ambitious — a MessageBus abstraction, AsyncToolMiddleware for background-offload-with-timeout, InboxMiddleware for result injection, WakeupDispatcher for idle-session activation, and SessionTurnGate for per-session mutual exclusion. Architecture is generally clean, but there are several concurrency and lifecycle issues in the new harness components that should be addressed before merge.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR introduces a comprehensive async tool and notification framework for agentscope-harness, alongside core improvements: HintBlock propagation through all formatters, String/Message convenience overloads on CallableAgent, userId/sessionId preservation in merged RuntimeContext, contextWindowSize builder support on chat models, and deterministic session IDs. The design is ambitious — a MessageBus abstraction, AsyncToolMiddleware for background-offload-with-timeout, InboxMiddleware for result injection, WakeupDispatcher for idle-session activation, and SessionTurnGate for per-session mutual exclusion. Architecture is generally clean, but there are several concurrency and lifecycle issues in the new harness components that should be addressed before merge.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
…form compatibility
…letion and error reporting
…t excessive firing
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…cope-ai#1802) This pull request introduces the RC4 release patches, which includes several important enhancements and fixes to the agent core and formatter modules. The main improvements include better support for plain text input APIs, more robust handling of tool execution and agent lifecycle, and extended support for `HintBlock` throughout the formatting pipeline. These changes improve developer ergonomics, error handling, and multimodal message compatibility. * **API Improvements, add String and Message overrides for agent `call()`** * **Formatter and Multimodal Message Support** * **Agent Execution and Error Handling** * **Runtime Context and State Management** * Improved merging of runtime contexts to preserve `userId` and `sessionId` during agent execution. * Enhanced state persistence by adding output messages to the mutable context before saving state to session. * Improved type-safe retrieval from string attributes in `RuntimeContext`. Overall, these changes streamline agent usage, enhance multimodal and hint support, and make the system more robust and developer-friendly.
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Additional engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - captureFlushRequest is wrapped in try/catch so exceptions (e.g. from List.copyOf or resolveAgentState) cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - MemoryFlushMiddleware: flush LLM call is capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - MemoryMaintenanceMiddleware: consolidate LLM call is capped by a 5-minute timeout. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - Detached work is bounded (MAX_PENDING_FLUSHES / MAX_PENDING_MAINTENANCE = 4): with a slow memory model the backlog is capped; excess runs are skipped and logged instead of accumulating without bound. Skipping is safe because a flush always extracts from the full conversation context - the next successful flush covers the same messages. - New opt-out MemoryConfig.asyncFlush(boolean), default true, for callers relying on "response completed == memory persisted" durability semantics: false chains the per-call memory work back onto the response stream via concatWith (bounded by the same 5-minute timeout; failures are logged and never fail the completed response). - captureFlushRequest is wrapped in try/catch so exceptions cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - Flush and consolidation LLM calls are capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. - English and Chinese memory guides document the detached default, the backlog cap, and the asyncFlush(false) opt-out. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. - onAgent_syncMode_waitsForFlush / onAgent_syncMode_waitsForMaintenance: with asyncFlush=false the response completion waits for the memory work. - scheduleFlush_backlogLimit_skipsBeyondCap: excess flushes beyond the cap are skipped, not queued (model invoked exactly MAX_PENDING_FLUSHES times). - memoryConfig_asyncFlush_defaultsTrue_andOptOut. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
…ponse MemoryFlushMiddleware and MemoryMaintenanceMiddleware appended their LLM-backed work via concatWith onto the returned Flux. Because ReActAgent.callInternal ends with takeLast(1), which can't emit until the upstream signals onComplete, callers consuming the agent response to completion (blockLast, takeLast(1), WebFlux controllers awaiting Mono<Msg>) ended up waiting for the full memory flush LLM call (19-27s per call) and consolidation LLM call (~44s first run). The original implementation used doOnComplete (fire-and-forget). A later commit (PR agentscope-ai#1802, RC4) swapped it for concatWith, introducing this regression. This fix restores the fire-and-forget behavior: both middlewares now subscribe their work independently of the returned Flux via doOnComplete().subscribe(), so the Flux completes as soon as the underlying agent call does. Engineering safeguards: - Both middlewares implement AutoCloseable and track pending Disposables in a Set guarded by synchronized(pending); a pre-subscribe closed check prevents new work, a post-subscribe check disposes any subscription that raced with close(). HarnessAgent.close() drains them (bounded by 5s) before workspace teardown to prevent races with temp dir deletion in tests and CLI shutdown. - Detached work is bounded (MAX_PENDING_FLUSHES / MAX_PENDING_MAINTENANCE = 4): with a slow memory model the backlog is capped; excess runs are skipped and logged instead of accumulating without bound. Skipping is safe because a flush always extracts from the full conversation context - the next successful flush covers the same messages. - New opt-out MemoryConfig.asyncFlush(boolean), default true, for callers relying on "response completed == memory persisted" durability semantics: false chains the per-call memory work back onto the response stream via concatWith (bounded by the same 5-minute timeout; failures are logged and never fail the completed response). - captureFlushRequest is wrapped in try/catch so exceptions cannot escape into the doOnComplete callback and turn an already-completed Flux into an error. - Flush and consolidation LLM calls are capped by a 5-minute timeout (after subscribeOn, measuring execution not queue wait) so a hung model provider cannot tie up a boundedElastic worker. - A FlushRequest record snapshots messages (List.copyOf) on the complete thread before background execution, avoiding races with mutable AgentState context. - English and Chinese memory guides document the detached default, the backlog cap, and the asyncFlush(false) opt-out. New regression tests (TDD): - onAgent_completesBeforeSlowFlushFinishes / completesBeforeSlowConsolidationFinishes: mock a slow LLM, assert Flux completes in <1s while the LLM is still running in the background. - onAgent_flushError_doesNotPropagateToFlux / maintenanceError_doesNotPropagateToFlux: verify errors in detached work never reach the caller. - onAgent_afterClose_doesNotScheduleNewFlush / doesNotScheduleNewMaintenance: verify close() prevents new work; uses polling (not fixed sleep) for deterministic verification on slow CI. - close_waitsForPendingFlush_thenReturns / waitsForPendingMaintenance_thenReturns: verify close() drains in-flight work before returning. - close_disposesHungFlush_andReturnsPromptly: verifies close() disposes a hanging model (Flux.never) and returns within CLOSE_AWAIT_TIMEOUT. - onAgent_syncMode_waitsForFlush / onAgent_syncMode_waitsForMaintenance: with asyncFlush=false the response completion waits for the memory work. - scheduleFlush_backlogLimit_skipsBeyondCap: excess flushes beyond the cap are skipped, not queued (model invoked exactly MAX_PENDING_FLUSHES times). - memoryConfig_asyncFlush_defaultsTrue_andOptOut. Fixes agentscope-ai#2276 Fixes agentscope-ai#2225
This pull request introduces the RC4 release patches, which includes several important enhancements and fixes to the agent core and formatter modules. The main improvements include better support for plain text input APIs, more robust handling of tool execution and agent lifecycle, and extended support for
HintBlockthroughout the formatting pipeline. These changes improve developer ergonomics, error handling, and multimodal message compatibility.call()userIdandsessionIdduring agent execution.RuntimeContext.Overall, these changes streamline agent usage, enhance multimodal and hint support, and make the system more robust and developer-friendly.