fix(agent,tools): adapt send_file to ctx-based channel injection after upstream refactor
Replace ContextualTool interface (removed upstream) with direct ctx reading in SendFileTool.Execute, using ToolChannel/ToolChatID helpers. Remove updateToolContexts which is no longer needed since ExecuteWithContext already injects channel/chatID into ctx for all tools. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e3b5c76877
commit
193a368bc8
2 changed files with 12 additions and 28 deletions
|
|
@ -1181,31 +1181,6 @@ func (al *AgentLoop) runLLMIteration(
|
||||||
return finalContent, iteration, nil
|
return finalContent, iteration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateToolContexts updates the context for tools that need channel/chatID info.
|
|
||||||
func (al *AgentLoop) updateToolContexts(agent *AgentInstance, channel, chatID string) {
|
|
||||||
// Use ContextualTool interface instead of type assertions
|
|
||||||
if tool, ok := agent.Tools.Get("message"); ok {
|
|
||||||
if mt, ok := tool.(tools.ContextualTool); ok {
|
|
||||||
mt.SetContext(channel, chatID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tool, ok := agent.Tools.Get("spawn"); ok {
|
|
||||||
if st, ok := tool.(tools.ContextualTool); ok {
|
|
||||||
st.SetContext(channel, chatID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tool, ok := agent.Tools.Get("subagent"); ok {
|
|
||||||
if st, ok := tool.(tools.ContextualTool); ok {
|
|
||||||
st.SetContext(channel, chatID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if tool, ok := agent.Tools.Get("send_file"); ok {
|
|
||||||
if sf, ok := tool.(tools.ContextualTool); ok {
|
|
||||||
sf.SetContext(channel, chatID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// maybeSummarize triggers summarization if the session history exceeds thresholds.
|
// maybeSummarize triggers summarization if the session history exceeds thresholds.
|
||||||
func (al *AgentLoop) maybeSummarize(agent *AgentInstance, sessionKey, channel, chatID string) {
|
func (al *AgentLoop) maybeSummarize(agent *AgentInstance, sessionKey, channel, chatID string) {
|
||||||
newHistory := agent.Sessions.GetHistory(sessionKey)
|
newHistory := agent.Sessions.GetHistory(sessionKey)
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,22 @@ func (t *SendFileTool) SetMediaStore(store media.MediaStore) {
|
||||||
t.mediaStore = store
|
t.mediaStore = store
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SendFileTool) Execute(_ context.Context, args map[string]any) *ToolResult {
|
func (t *SendFileTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
|
||||||
path, _ := args["path"].(string)
|
path, _ := args["path"].(string)
|
||||||
if strings.TrimSpace(path) == "" {
|
if strings.TrimSpace(path) == "" {
|
||||||
return ErrorResult("path is required")
|
return ErrorResult("path is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.defaultChannel == "" || t.defaultChatID == "" {
|
// Prefer context-injected channel/chatID (set by ExecuteWithContext), fall back to SetContext values.
|
||||||
|
channel := ToolChannel(ctx)
|
||||||
|
if channel == "" {
|
||||||
|
channel = t.defaultChannel
|
||||||
|
}
|
||||||
|
chatID := ToolChatID(ctx)
|
||||||
|
if chatID == "" {
|
||||||
|
chatID = t.defaultChatID
|
||||||
|
}
|
||||||
|
if channel == "" || chatID == "" {
|
||||||
return ErrorResult("no target channel/chat available")
|
return ErrorResult("no target channel/chat available")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +117,7 @@ func (t *SendFileTool) Execute(_ context.Context, args map[string]any) *ToolResu
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaType := detectMediaType(resolved)
|
mediaType := detectMediaType(resolved)
|
||||||
scope := fmt.Sprintf("tool:send_file:%s:%s", t.defaultChannel, t.defaultChatID)
|
scope := fmt.Sprintf("tool:send_file:%s:%s", channel, chatID)
|
||||||
|
|
||||||
ref, err := t.mediaStore.Store(resolved, media.MediaMeta{
|
ref, err := t.mediaStore.Store(resolved, media.MediaMeta{
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue