feat(agent): add AgentDispatcher execution seam#58
Merged
Conversation
Introduce an opt-in seam so embedders can execute spawned sub-agents out-of-process (e.g. dispatch to a remote worker) while cogito keeps owning all lifecycle bookkeeping: registration, status, done, callbacks, completion injection, and detach. A nil dispatcher preserves the existing in-process behavior exactly; ErrDispatchFallback lets a dispatcher defer a given spawn back to the in-process path. New API: AgentRunSpec, AgentEvent, AgentDispatcher, ErrDispatchFallback, WithAgentDispatcher. runAgent branches on the dispatcher; spawn builds an AgentRunSpec (resolved persona/tools/model) and an optional Emit stream. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in execution seam so embedders can run spawned sub-agents out of process (e.g. dispatch to a remote worker over a message bus) while cogito keeps owning all sub-agent lifecycle bookkeeping.
Why
Today
spawn_agentalways runs the sub-agent loop in-process (go runAgent→ recursiveExecuteTools). The only extension point is the LLM factory (which model to talk to), not where the loop runs. Distributed embedders therefore have to reimplement cogito's entire agent-lifecycle layer (registry, status, completion notification, detach) on top of their own transport. This seam lets them reuse cogito's lifecycle and only supply the transport.API
Behavior
donechannel, spawn/completion callbacks, and the completion injection into the parent loop. The dispatcher only returns the finalFragment.ErrDispatchFallback→ defer a given spawn back to the in-process path.runAgentbranches on the dispatcher; spawn builds anAgentRunSpec(resolved persona/tools/model) and an optionalEmitstream tagged with the agent ID.Tests
New
agent_dispatcher_test.go: foreground dispatch, background dispatch (asserts cogito auto-injects completion),ErrDispatchFallback, and nil-dispatcher (existing behavior preserved). All green. No changes to existing in-process agent semantics.🤖 Generated with Claude Code