Skip to content

Commit b5e7104

Browse files
authored
Merge pull request #515 from dgageot/fix-514
Temporary fix to exclude todo tools from code Mode
2 parents 001c465 + 54032f9 commit b5e7104

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

pkg/codemode/codemode.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ func (c *codeModeTool) Instructions() string {
4646
return ""
4747
}
4848

49+
func isExcludedTool(tool tools.Tool) bool {
50+
// TODO(dga): make this more robust. It really a temporary hack to exclude the todo tools.
51+
// See #514
52+
return strings.Contains(tool.Name, "_todo")
53+
}
54+
4955
func (c *codeModeTool) Tools(ctx context.Context) ([]tools.Tool, error) {
50-
var functionsDoc []string
56+
var (
57+
functionsDoc []string
58+
excludedTools []tools.Tool
59+
)
5160

5261
for _, toolset := range c.toolsets {
5362
allTools, err := toolset.Tools(ctx)
@@ -56,11 +65,15 @@ func (c *codeModeTool) Tools(ctx context.Context) ([]tools.Tool, error) {
5665
}
5766

5867
for _, tool := range allTools {
59-
functionsDoc = append(functionsDoc, toolToJsDoc(tool))
68+
if isExcludedTool(tool) {
69+
excludedTools = append(excludedTools, tool)
70+
} else {
71+
functionsDoc = append(functionsDoc, toolToJsDoc(tool))
72+
}
6073
}
6174
}
6275

63-
return []tools.Tool{{
76+
allTools := []tools.Tool{{
6477
Name: "run_tools_with_javascript",
6578
Description: prompt + strings.Join(functionsDoc, "\n"),
6679
Parameters: tools.MustSchemaFor[RunToolsWithJavascriptArgs](),
@@ -88,7 +101,11 @@ func (c *codeModeTool) Tools(ctx context.Context) ([]tools.Tool, error) {
88101
Annotations: tools.ToolAnnotations{
89102
Title: "Run tools with Javascript",
90103
},
91-
}}, nil
104+
}}
105+
106+
allTools = append(allTools, excludedTools...)
107+
108+
return allTools, nil
92109
}
93110

94111
func (c *codeModeTool) Start(ctx context.Context) error {

pkg/teamloader/teamloader.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,12 @@ func LoadWithOverrides(ctx context.Context, path string, runtimeConfig config.Ru
173173
return nil, fmt.Errorf("failed to get tools: %w", err)
174174
}
175175

176+
if len(a.SubAgents) > 0 {
177+
agentTools = append(agentTools, builtin.NewTransferTaskTool())
178+
}
179+
176180
if len(agentTools) > 0 {
177-
if agentConfig.CodeModeTools || runtimeConfig.GlobalCodeMode {
178-
codemodeTool := codemode.Wrap(agentTools)
179-
opts = append(opts, agent.WithToolSets(codemodeTool))
180-
} else {
181-
opts = append(opts, agent.WithToolSets(agentTools...))
182-
}
181+
opts = append(opts, agent.WithToolSets(agentTools...))
183182
}
184183

185184
ag := agent.New(name, agentConfig.Instruction, opts...)
@@ -237,10 +236,6 @@ func getModelsForAgent(ctx context.Context, cfg *latest.Config, a *latest.AgentC
237236
func getToolsForAgent(ctx context.Context, a *latest.AgentConfig, parentDir string, envProvider environment.Provider, runtimeConfig config.RuntimeConfig) ([]tools.ToolSet, error) {
238237
var t []tools.ToolSet
239238

240-
if len(a.SubAgents) > 0 {
241-
t = append(t, builtin.NewTransferTaskTool())
242-
}
243-
244239
for i := range a.Toolsets {
245240
toolset := a.Toolsets[i]
246241

@@ -252,7 +247,16 @@ func getToolsForAgent(ctx context.Context, a *latest.AgentConfig, parentDir stri
252247
t = append(t, WithInstructions(tool, a.Instruction))
253248
}
254249

255-
return t, nil
250+
if !a.CodeModeTools && !runtimeConfig.GlobalCodeMode {
251+
return t, nil
252+
}
253+
254+
// Wrap all tools in a single Code Mode toolset.
255+
// This allows the agent to call multiple tools in a single response.
256+
// It also allows to combine the results of multiple tools in a single response.
257+
return []tools.ToolSet{
258+
codemode.Wrap(t),
259+
}, nil
256260
}
257261

258262
func createTool(ctx context.Context, toolset latest.Toolset, a *latest.AgentConfig, parentDir string, envProvider environment.Provider, runtimeConfig config.RuntimeConfig) (tools.ToolSet, error) {

0 commit comments

Comments
 (0)