Skip to content

Commit 9fab92e

Browse files
committed
Better handling of user tools
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 3a978f6 commit 9fab92e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

core/agent/agent.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
782782
cogitoTools := availableActions.ToCogitoTools(job.GetContext(), a.sharedState)
783783

784784
var err error
785+
var userTool bool
785786

786787
cogitoOpts := []cogito.Option{
787788
cogito.WithMCPs(a.mcpSessions...),
@@ -985,7 +986,8 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
985986
a.llm, fragment,
986987
cogitoOpts...,
987988
)
988-
if err != nil && !errors.Is(err, cogito.ErrNoToolSelected) && !errors.Is(err, cogito.ErrGoalNotAchieved) {
989+
990+
if err != nil && !errors.Is(err, cogito.ErrNoToolSelected) && !errors.Is(err, cogito.ErrGoalNotAchieved) && !userTool {
989991
if obs != nil {
990992
obs.Completion = &types.Completion{
991993
Error: err.Error(),
@@ -997,6 +999,11 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
997999
return
9981000
}
9991001

1002+
if userTool {
1003+
job.Result.Finish(nil)
1004+
return
1005+
}
1006+
10001007
if len(fragment.Messages) > 0 &&
10011008
fragment.LastMessage().Role == "tool" {
10021009
toolToCall := fragment.Messages[len(fragment.Messages)-2].ToolCalls[0].Function.Name

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/google/go-github/v69 v69.2.0
1717
github.com/google/uuid v1.6.0
1818
github.com/modelcontextprotocol/go-sdk v1.0.0
19-
github.com/mudler/cogito v0.3.4-0.20251022151954-5f46a5b9e3c4
19+
github.com/mudler/cogito v0.3.4-0.20251023130443-7ff6cae505b1
2020
github.com/onsi/ginkgo/v2 v2.25.3
2121
github.com/onsi/gomega v1.38.2
2222
github.com/philippgille/chromem-go v0.7.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ github.com/mudler/cogito v0.3.4-0.20251021205807-8b24a604fc4f h1:C+cRbVD8qDTgfOj
208208
github.com/mudler/cogito v0.3.4-0.20251021205807-8b24a604fc4f/go.mod h1:abMwl+CUjCp87IufA2quZdZt0bbLaHHN79o17HbUKxU=
209209
github.com/mudler/cogito v0.3.4-0.20251022151954-5f46a5b9e3c4 h1:VwEEePUqeL+Lwu0nxMc2oRxlMx4dm5MZ48CyorpiYEA=
210210
github.com/mudler/cogito v0.3.4-0.20251022151954-5f46a5b9e3c4/go.mod h1:abMwl+CUjCp87IufA2quZdZt0bbLaHHN79o17HbUKxU=
211+
github.com/mudler/cogito v0.3.4-0.20251023130443-7ff6cae505b1 h1:JdB5ttL4P6N+oaVdYZZCZfos3SKOHiyhBTmMIGAiWbU=
212+
github.com/mudler/cogito v0.3.4-0.20251023130443-7ff6cae505b1/go.mod h1:abMwl+CUjCp87IufA2quZdZt0bbLaHHN79o17HbUKxU=
211213
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
212214
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
213215
github.com/onsi/ginkgo/v2 v2.25.3 h1:Ty8+Yi/ayDAGtk4XxmmfUy4GabvM+MegeB4cDLRi6nw=

0 commit comments

Comments
 (0)