feat(ai-core): wire function calling into the LLM pipeline

- llm: ChatStreamWithTools sends OpenAI-format tools; streamed tool_call
  deltas are reassembled by index into complete ToolCalls on the Done token
- model: LLMMessage gains ToolCallID/ToolCalls; StreamToken gains ToolCalls
- orchestrator: new ToolExecutor interface and streamWithTools loop —
  execute requested tools, feed results back, up to 3 rounds, final round
  forces a plain text answer; normal chats still stream token by token.
  Also adds Pipeline.FinishRound (assistant reply recording + post-round
  hook), wired to transports in the next commit.
- main: inject the plugin registry via toolExecAdapter

Includes an httptest-based test covering delta reassembly, tool
execution, and result feedback.
This commit is contained in:
Aska committed 2026-08-20 19:40:58 +08:00
1 parent 9a3c77dbd3
commit 7c02d31194
5 files changed
+384 -11

No files matched your search

+10 -3
View File
@@ -42,6 +42,11 @@ type LLMMessage struct {
Role string `json:"role"` // "system" | "user" | "assistant" | "tool"
Content string `json:"content"`
Name string `json:"name,omitempty"`
// ToolCallID links a tool result message to the call that produced it (role="tool").
ToolCallID string `json:"tool_call_id,omitempty"`
// ToolCalls carries the calls requested by the assistant (role="assistant").
// Marshaled to the OpenAI wire format by the llm package, hence "-".
ToolCalls []ToolCall `json:"-"`
}
// LLMResponse represents a non-streaming LLM response.
@@ -54,9 +59,11 @@ type LLMResponse struct {
// StreamToken is a single token from a streaming LLM response.
type StreamToken struct {
Content string `json:"content"`
FinishReason string `json:"finish_reason,omitempty"`
Done bool `json:"done"`
Content string `json:"content"`
FinishReason string `json:"finish_reason,omitempty"`
Done bool `json:"done"`
// ToolCalls is set on the final Done token when the model requested tool calls.
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
// ReviewSegment represents a parsed action/chat segment from LLM output.