Skip to content

feat(agent): implement tool-use orchestration loop #79

Description

@Svagtlys

feat(agent): implement tool-use orchestration loop

Description

Implement the orchestration loop that detects tool calls in the LLM response, executes them via the MCP Connector, and feeds the results back into the inference engine for the final response. This is the core "reason → act → observe" cycle that enables agentic tool use.

Why

Without this loop, the LLM can receive tool definitions but the harness cannot act on the tool call requests the LLM generates. This is the missing piece that wires inference → MCP execution → final synthesis together.

Scope

  • Add tool_calls field to CompletionResult type to capture structured tool invocation requests from the LLM
  • Detect finish_reason == "tool_calls" and route to MCP Connector for execution
  • Map LLM tool call payload (name + arguments) → MCP tools/call request
  • Wrap MCP execution result into provider-native tool message format
  • Append tool result to message history and trigger follow-up completion call
  • Support multi-tool-call responses (LLM requests multiple tools in a single turn)
  • Handle tool execution errors (surface error content back to LLM as tool result)

Depends on: #8, #15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions