refact: openai-go#30
Merged
Merged
Conversation
- assistant消息携带reasoning时通过SetExtraFields注入reasoning_content字段,确保DeepSeek thinking模式多轮对话正常 - executor/conductor构建assistant消息时携带Reasoning字段,保持reasoning在多轮LLM调用中传递 - streaming模式下从delta raw JSON提取并累加reasoning_content - 修复openai.ToolMessage(content, toolCallID)参数顺序反了导致tool_call_id不匹配 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's GuideRefactors the LLM integration by introducing a provider-agnostic internal Engine interface backed by the official openai-go SDK, replacing langchaingo (and Bedrock), updating agents, tools, and tests to use the new abstractions, simplifying logging, and cleaning up dependencies. Sequence diagram for ConductorAgent tool-calling loop using EnginesequenceDiagram
actor User
participant CodingAssistant
participant ConductorAgent
participant Engine
participant ToolAdapter
participant ToolImpl as ToolImplementation
participant Memory as ConversationMemory
User->>CodingAssistant: ProcessCodingTaskWithCallback / ProcessConversation
CodingAssistant->>CodingAssistant: Init(engine, workDir)
CodingAssistant->>ConductorAgent: Run(ctx, input, memory)
loop up to maxSteps
ConductorAgent->>ConductorAgent: Build messages []Message
ConductorAgent->>ConductorAgent: Build toolDefs []ToolDef
ConductorAgent->>Engine: GenerateContent(ctx, messages, toolDefs, nil)
Engine-->>ConductorAgent: Response{Choices[0]}
alt assistant returns content
ConductorAgent->>Memory: AddAssistantMessage(content, toolCalls)
end
alt no toolCalls
ConductorAgent-->>CodingAssistant: final content
CodingAssistant-->>User: final answer
else has toolCalls
loop for each ToolCall
ConductorAgent->>ToolAdapter: Call(ctx, function.Arguments)
ToolAdapter->>ToolImpl: Execute(ctx, params)
ToolImpl-->>ToolAdapter: toolResult
ToolAdapter-->>ConductorAgent: toolResult
ConductorAgent->>Memory: AddToolMessage(toolResult, toolCall.ID)
ConductorAgent->>ConductorAgent: Append tool Message {RoleTool, Content, ToolCallID, ToolName}
end
end
end
Class diagram for new LLM Engine abstractions and agentsclassDiagram
direction LR
class Engine {
<<interface>>
+GenerateContent(ctx context.Context, messages []Message, tools []ToolDef, opts *CallOptions) *Response
}
class OpenAIEngine {
-client *openai.Client
-model string
+NewOpenAIEngine(baseURL string, apiKey string, model string) OpenAIEngine
+GenerateContent(ctx context.Context, messages []Message, tools []ToolDef, opts *CallOptions) *Response
-buildParams(messages []Message, tools []ToolDef, opts *CallOptions) openai.ChatCompletionNewParams
-generateStreaming(ctx context.Context, params openai.ChatCompletionNewParams, handler StreamHandler) *Response
-convertMessages(messages []Message) []openai.ChatCompletionMessageParamUnion
-convertMessage(msg Message) openai.ChatCompletionMessageParamUnion
-buildAssistantWithToolCalls(msg Message) openai.ChatCompletionMessageParamUnion
-convertTools(tools []ToolDef) []openai.ChatCompletionToolUnionParam
-toResponse(completion *openai.ChatCompletion) *Response
}
class LoggingEngine {
-inner Engine
+GenerateContent(ctx context.Context, messages []Message, tools []ToolDef, opts *CallOptions) *Response
}
class Client {
+Engine Engine
+Config *config.Config
+NewClient(config *config.Config) *Client
+GenerateCompletionWithMemory(ctx context.Context, memory []Message, streamHandler func(context.Context, []byte) error) string
}
class CallOptions {
+MaxTokens int
+Temperature float64
+StreamHandler StreamHandler
}
class Message {
+Role Role
+Content string
+ToolCalls []ToolCall
+ToolCallID string
+ToolName string
+Reasoning string
}
class Role {
<<enumeration>>
RoleSystem
RoleUser
RoleAssistant
RoleTool
}
class ToolDef {
+Type string
+Function FunctionDef
}
class FunctionDef {
+Name string
+Description string
+Parameters map~string,any~
}
class ToolCall {
+ID string
+Type string
+Function FunctionCall
}
class FunctionCall {
+Name string
+Arguments string
}
class Response {
+Choices []Choice
}
class Choice {
+Content string
+ToolCalls []ToolCall
+Reasoning string
}
class CodingAssistant {
-engine Engine
-config *config.Config
-conductor *agents.ConductorAgent
+Init(engine Engine, workDir string)
+ProcessCodingTaskWithCallback(req *TaskRequest) string
+ProcessConversation(req *TaskRequest) string
}
class BaseAgent {
+LLM Engine
+Publisher *messaging.MessagePublisher
}
class ConductorAgent {
+BaseAgent
+Run(ctx context.Context, input string, mem *memory.ConversationMemory) string
}
class RepoAgent {
+BaseAgent
}
class CodingAgent {
+BaseAgent
}
class ChatAgent {
+BaseAgent
}
class MetaAgent {
+BaseAgent
+Run(ctx context.Context, input string) string
}
class ExecutorConfig {
+SystemPrompt string
+UserInput string
+Adapters []*tools.Adapter
+LLM Engine
+MaxSteps int
+Publisher *messaging.MessagePublisher
+AgentName string
+StopOnFinish bool
+SystemAsHuman bool
+OnToolResult func(name string, result string)
}
class MicroAgentTool {
+LLM Engine
+NewMicroAgentTool(llm Engine) *MicroAgentTool
+Execute(ctx context.Context, params map~string,any~) any
}
class Adapter {
-name string
-description string
-schema map~string,any~
-fn ToolFunc
-guard *WorkspaceGuard
+ToToolDef() ToolDef
}
Engine <|.. OpenAIEngine
Engine <|.. LoggingEngine
Client o--> Engine
Client --> CallOptions
Client --> Message
Client --> Response
CodingAssistant o--> Engine
CodingAssistant --> ConductorAgent
BaseAgent o--> Engine
ConductorAgent --> BaseAgent
RepoAgent --> BaseAgent
CodingAgent --> BaseAgent
ChatAgent --> BaseAgent
MetaAgent --> BaseAgent
ExecutorConfig o--> Engine
MicroAgentTool o--> Engine
Message --> Role
Message --> ToolCall
ToolDef --> FunctionDef
ToolCall --> FunctionCall
Response --> Choice
Choice --> ToolCall
Adapter ..> ToolDef
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Summary by Sourcery
Replace langchaingo-based LLM integration with a custom OpenAI Engine abstraction and adapt agents, tools, and app code to use it.
Enhancements:
Build:
Tests: