Skip to content

Commit 63ccd37

Browse files
committed
fix: functions to tools
1 parent 77b2d7b commit 63ccd37

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

agents/openai_functions_agent.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,21 @@ func NewOpenAIFunctionsAgent(llm llms.Model, tools []tools.Tool, opts ...Option)
4848
}
4949
}
5050

51-
func (o *OpenAIFunctionsAgent) functions() []llms.FunctionDefinition {
52-
res := make([]llms.FunctionDefinition, 0)
51+
func (o *OpenAIFunctionsAgent) tools() []llms.Tool {
52+
res := make([]llms.Tool, 0)
5353
for _, tool := range o.Tools {
54-
res = append(res, llms.FunctionDefinition{
55-
Name: tool.Name(),
56-
Description: tool.Description(),
57-
Parameters: map[string]any{
58-
"properties": map[string]any{
59-
"__arg1": map[string]string{"title": "__arg1", "type": "string"},
54+
res = append(res, llms.Tool{
55+
Type: "function",
56+
Function: &llms.FunctionDefinition{
57+
Name: tool.Name(),
58+
Description: tool.Description(),
59+
Parameters: map[string]any{
60+
"properties": map[string]any{
61+
"__arg1": map[string]string{"title": "__arg1", "type": "string"},
62+
},
63+
"required": []string{"__arg1"},
64+
"type": "object",
6065
},
61-
"required": []string{"__arg1"},
62-
"type": "object",
6366
},
6467
})
6568
}
@@ -130,7 +133,7 @@ func (o *OpenAIFunctionsAgent) Plan(
130133
}
131134

132135
result, err := o.LLM.GenerateContent(ctx, mcList,
133-
llms.WithFunctions(o.functions()), llms.WithStreamingFunc(stream))
136+
llms.WithTools(o.tools()), llms.WithStreamingFunc(stream))
134137
if err != nil {
135138
return nil, nil, err
136139
}
@@ -180,8 +183,20 @@ func (o *OpenAIFunctionsAgent) constructScratchPad(steps []schema.AgentStep) []l
180183

181184
messages := make([]llms.ChatMessage, 0)
182185
for _, step := range steps {
183-
messages = append(messages, llms.FunctionChatMessage{
184-
Name: step.Action.Tool,
186+
messages = append(messages, llms.AIChatMessage{
187+
ToolCalls: []llms.ToolCall{
188+
{
189+
ID: step.Action.ToolID,
190+
Type: "function",
191+
FunctionCall: &llms.FunctionCall{
192+
Name: step.Action.Tool,
193+
Arguments: step.Action.ToolInput,
194+
},
195+
},
196+
},
197+
})
198+
messages = append(messages, llms.ToolChatMessage{
199+
ID: step.Action.ToolID,
185200
Content: step.Observation,
186201
})
187202
}

0 commit comments

Comments
 (0)