refactor(agent): update buildAgentContext to include assistantID
- Modified the buildAgentContext function to accept assistantID as a parameter, enhancing the context building process for agent calls. - Updated multiple Call methods to pass the assistantID, ensuring proper context management during agent interactions.
This commit is contained in:
parent
abde3adf13
commit
2b0ac0d270
1 changed files with 5 additions and 4 deletions
|
|
@ -191,7 +191,7 @@ func (c *AgentCaller) Call(ctx *robottypes.Context, assistantID string, messages
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert robot context to agent context
|
// Convert robot context to agent context
|
||||||
agentCtx := c.buildAgentContext(ctx)
|
agentCtx := c.buildAgentContext(ctx, assistantID)
|
||||||
defer agentCtx.Release() // IMPORTANT: Release agent context to prevent resource leaks
|
defer agentCtx.Release() // IMPORTANT: Release agent context to prevent resource leaks
|
||||||
|
|
||||||
// Call assistant with streaming
|
// Call assistant with streaming
|
||||||
|
|
@ -294,7 +294,7 @@ func (c *AgentCaller) CallStream(ctx *robottypes.Context, assistantID string, me
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
agentCtx := c.buildAgentContext(ctx)
|
agentCtx := c.buildAgentContext(ctx, assistantID)
|
||||||
defer agentCtx.Release()
|
defer agentCtx.Release()
|
||||||
|
|
||||||
response, err := ast.Stream(agentCtx, messages, opts)
|
response, err := ast.Stream(agentCtx, messages, opts)
|
||||||
|
|
@ -353,7 +353,7 @@ func (c *AgentCaller) CallStreamRaw(ctx *robottypes.Context, assistantID string,
|
||||||
opts.OnMessage = onMessage
|
opts.OnMessage = onMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
agentCtx := c.buildAgentContext(ctx)
|
agentCtx := c.buildAgentContext(ctx, assistantID)
|
||||||
defer agentCtx.Release()
|
defer agentCtx.Release()
|
||||||
|
|
||||||
response, err := ast.Stream(agentCtx, messages, opts)
|
response, err := ast.Stream(agentCtx, messages, opts)
|
||||||
|
|
@ -390,7 +390,7 @@ func (c *AgentCaller) CallWithMessagesStreamRaw(ctx *robottypes.Context, assista
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildAgentContext converts robot context to agent context
|
// buildAgentContext converts robot context to agent context
|
||||||
func (c *AgentCaller) buildAgentContext(ctx *robottypes.Context) *agentcontext.Context {
|
func (c *AgentCaller) buildAgentContext(ctx *robottypes.Context, assistantID string) *agentcontext.Context {
|
||||||
// Build authorized info for agent context
|
// Build authorized info for agent context
|
||||||
var authorized *oauthtypes.AuthorizedInfo
|
var authorized *oauthtypes.AuthorizedInfo
|
||||||
if ctx.Auth != nil {
|
if ctx.Auth != nil {
|
||||||
|
|
@ -403,6 +403,7 @@ func (c *AgentCaller) buildAgentContext(ctx *robottypes.Context) *agentcontext.C
|
||||||
// Create a new agent context
|
// Create a new agent context
|
||||||
// Use ChatID for multi-turn conversations, empty for single calls
|
// Use ChatID for multi-turn conversations, empty for single calls
|
||||||
agentCtx := agentcontext.New(ctx.Context, authorized, c.ChatID)
|
agentCtx := agentcontext.New(ctx.Context, authorized, c.ChatID)
|
||||||
|
agentCtx.AssistantID = assistantID
|
||||||
|
|
||||||
// Propagate locale to agent context; fall back to "en" so that
|
// Propagate locale to agent context; fall back to "en" so that
|
||||||
// i18n.Tr / buildBoxDisplayName always resolve {{name}} templates.
|
// i18n.Tr / buildBoxDisplayName always resolve {{name}} templates.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue