Re-architecture draft: multiple parallel workers, demo with web ui and JSON mode #3228
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.
Summary
This branch introduces infrastructure to maintain multiple parallel workers. This infrastructure is also agnostic of UI implementation, and allows to work with various UIs.
The ultimate goals of this effort are:
Demo
TBD
Structure
1: Core Execution Components
Session
Purpose: Central orchestrator managing all workers and jobs in the system.
Key Responsibilities:
Key Methods:
build_worker(name)- Creates new worker with model providerrun_agent_loop(worker, input, ui_interface)- Launches agent loop taskcancel_all_jobs()- Cancels all active jobscleanup_inactive_jobs()- Removes old completed jobs (keeps last 3)wait_for_all_jobs()- Blocks until all jobs completeLocation:
crates/chat-cli/src/agent_env/session.rsWorker
Purpose: Complete AI agent configuration containing state, context, and model provider.
Key Components:
id: Uuid- Unique identifiername: String- Human-readable namecontext_container: ContextContainer- Conversation history and contextmodel_provider: Arc<dyn ModelProvider>- LLM communication interfacestate: WorkerStates- Current execution statelast_failure: Option<String>- Error trackingState Machine:
States:
Inactive- Ready for new taskWorking- Preparing requestRequesting- Sending to LLMReceiving- Streaming responseWaiting- Awaiting user inputUsingTool- Executing toolInactiveFailed- Task failedLocation:
crates/chat-cli/src/agent_env/worker.rsWorkerTask (Trait)
Purpose: Interface for executable work units that run on workers.
Contract:
Implementations:
AgentLoop- Main conversational agent loop (worker_tasks/agent_loop.rs)ProtoLoop- Demo/prototype task (demo/proto_loop.rs)Location:
crates/chat-cli/src/agent_env/worker_task.rsWorkerJob
Purpose: Running instance combining Worker + Task + execution infrastructure.
Key Components:
worker: Arc<Worker>- Worker executing the taskworker_task: Arc<dyn WorkerTask>- Task being executedcancellation_token: CancellationToken- Cancellation mechanismtask_handle: JoinHandle- Tokio task handleworker_job_continuations: Continuations- Completion callbacksLifecycle:
new()- Create job (not started)launch()- Spawn async taskcancel()- Request cancellationwait()- Block until completionJob States:
Active- Currently runningCompleted- Finished successfullyCancelled- User/system cancelledFailed- Error occurredContinuations: Callbacks registered via
worker_job_continuations.add_or_run_now()that execute when job completes. Used to chain actions (e.g., re-queue prompt after agent response).Locations:
crates/chat-cli/src/agent_env/worker_job.rscrates/chat-cli/src/agent_env/worker_job_continuations.rs2: Model and Context Infrastructure
ModelProvider (Trait)
Purpose: Abstraction for LLM communication supporting streaming responses.
Contract:
Key Types:
ModelRequest- Contains prompt stringModelResponseChunk- Streaming chunks (text or tool requests)ModelResponse- Complete response with tool requestsImplementations:
BedrockConverseStream- AWS Bedrock integration (model_providers/bedrock_converse_stream.rs)Location:
crates/chat-cli/src/agent_env/model_providers/model_provider.rsContextContainer
Purpose: Manages all contextual information available to a worker.
Structure:
ConversationHistory:
push_input_message(content)- Add user messagepush_assistant_message(assistant)- Add assistant responseget_entries()- Retrieve all messagesConversationEntry:
UserMessageorAssistantMessageLocation:
crates/chat-cli/src/agent_env/context_container/4: User Interface and web support
TBD