Skip to content

feat: Introduce AgentRuntimeFactory and refactor agent turn handling#11

Merged
NoOne7135 merged 3 commits into
mainfrom
refactor
Jun 9, 2026
Merged

feat: Introduce AgentRuntimeFactory and refactor agent turn handling#11
NoOne7135 merged 3 commits into
mainfrom
refactor

Conversation

@NoOne7135

Copy link
Copy Markdown
Contributor
  • Added AgentRuntimeFactory to encapsulate AgentRuntime creation logic.
  • Refactored simpleAgent.ts to streamline agent execution and remove deprecated code.
  • Implemented SpeechTurnService for handling speech input and response processing.
  • Created AgentToolProvider for managing API-based tools.
  • Introduced TurnLifecycleService and TurnPersistenceService for managing turn state and persistence.
  • Added TurnPromptBuilder for constructing prompts based on user input and context.
  • Implemented TurnStreamConsumer and VegaLiteStreamBuffer for processing streaming responses.
  • Updated turnTypes.ts to define new types for agent turn handling.
  • Refactored AgentTurnService to utilize new services and improve code organization.

NoOne7135 added 2 commits June 9, 2026 13:36
- Added AgentRuntimeFactory to encapsulate AgentRuntime creation logic.
- Refactored simpleAgent.ts to streamline agent execution and remove deprecated code.
- Implemented SpeechTurnService for handling speech input and response processing.
- Created AgentToolProvider for managing API-based tools.
- Introduced TurnLifecycleService and TurnPersistenceService for managing turn state and persistence.
- Added TurnPromptBuilder for constructing prompts based on user input and context.
- Implemented TurnStreamConsumer and VegaLiteStreamBuffer for processing streaming responses.
- Updated turnTypes.ts to define new types for agent turn handling.
- Refactored AgentTurnService to utilize new services and improve code organization.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors agent “turn” execution into smaller services (lifecycle, context building, prompt building, runtime streaming, and stream consumption) and moves speech handling out of AgentTurnService, aiming to make turn handling more modular and maintainable.

Changes:

  • Rewires plugin initialization to build a composed AgentTurnService plus a dedicated SpeechTurnService.
  • Introduces new turn/runtime abstractions (AgentRuntime, Turn* services, stream consumer/buffer, new turn types).
  • Updates tool event wiring to use context.emit and route tool-call observability through the API tools middleware.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
index.ts Constructs the new runtime/tooling/turn services and wires handleSpeechTurn to SpeechTurnService.
agentTurnService.ts Refactors turn preparation/execution/persistence around new services and removes inline speech handling.
agent/turn/VegaLiteStreamBuffer.ts New buffering logic for vega-lite fenced blocks while streaming text deltas.
agent/turn/turnTypes.ts New shared types for turn inputs, prepared turns, runtime inputs, and results.
agent/turn/TurnStreamConsumer.ts New streaming consumer extracting reasoning/text deltas and using the vega-lite buffer.
agent/turn/TurnPromptBuilder.ts New prompt builder (system prompt + language detection + user message).
agent/turn/TurnPersistenceService.ts New persistence wrapper for touching sessions and updating turn responses/debug.
agent/turn/TurnLifecycleService.ts New lifecycle wrapper for start/finish (create turn + persist response).
agent/turn/TurnContextBuilder.ts New context builder with defaults for time zone and admin public origin.
agent/tools/navigateUser.ts Renames context event emitter field from emitAgentEvent to emit.
agent/tools/AgentToolProvider.ts New provider encapsulating API-based tool prep + tool list creation.
agent/speech/SpeechTurnService.ts New speech turn handler (transcribe → run agent → synthesize/stream audio).
agent/simpleAgent.ts Removes deprecated agent runner and exports middleware type + metrics logger used by runtime.
agent/runtime/AgentRuntime.ts New runtime that creates the langchain agent, middleware chain, and streams messages.
agent/runtime/AgentContext.ts New runtime context schema and adapter (toLangchainAgentContext).
agent/models/AgentModeResolver.ts New resolver for selecting a mode by name (or default).
agent/models/AgentModelFactory.ts New factory for creating primary/summary models and model middleware.
agent/middleware/apiBasedTools.ts Emits tool-call events via context.emit and records them in sequenceDebugSink.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index.ts
Comment thread agent/turn/VegaLiteStreamBuffer.ts
@NoOne7135 NoOne7135 merged commit 67e14dc into main Jun 9, 2026
2 checks passed
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.

2 participants