From 4a42ec04870f8d5ad7a568c74f59c090616ca227 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 17 Apr 2024 00:40:53 +0200 Subject: [PATCH] give reasoning when expanding parameters --- agent/actions.go | 7 +++++-- agent/agent.go | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/agent/actions.go b/agent/actions.go index bd23fcb..c19a0b8 100644 --- a/agent/actions.go +++ b/agent/actions.go @@ -72,7 +72,7 @@ func (a *Agent) decision( } if len(resp.Choices) != 1 { - return nil, fmt.Errorf("no choices") + return nil, fmt.Errorf("no choices: %d", len(resp.Choices)) } msg := resp.Choices[0].Message @@ -131,7 +131,10 @@ func (a *Agent) generateParameters(ctx context.Context, pickTemplate string, act } return a.decision(ctx, - conversation, + append(conversation, openai.ChatCompletionMessage{ + Role: "system", + Content: fmt.Sprintf("The agent decided to use the tool %s with the following reasoning: %s", act.Definition().Name, reasoning), + }), a.systemInternalActions().ToTools(), openai.ToolChoice{ Type: openai.ToolTypeFunction, diff --git a/agent/agent.go b/agent/agent.go index f4bee93..e949d1f 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -367,7 +367,11 @@ func (a *Agent) consumeJob(job *Job, role string) { return } - a.logger.Info("===> Generating parameters for", "action", chosenAction.Definition().Name) + a.logger.Info("Generating parameters", + "agent", a.Character.Name, + "action", chosenAction.Definition().Name, + "reasoning", reasoning, + ) params, err := a.generateParameters(ctx, pickTemplate, chosenAction, a.currentConversation, reasoning) if err != nil { @@ -375,8 +379,13 @@ func (a *Agent) consumeJob(job *Job, role string) { return } - a.logger.Info("===> Generated parameters for", "action", chosenAction.Definition().Name) - a.logger.Info(params.actionParams.String()) + a.logger.Info( + "Generated parameters", + "agent", a.Character.Name, + "action", chosenAction.Definition().Name, + "reasoning", reasoning, + "params", params.actionParams.String(), + ) if params.actionParams == nil { job.Result.Finish(fmt.Errorf("no parameters"))