Skip to content

Commit 30e94e8

Browse files
committed
fix: out-of bounds messages and spelling
1 parent 36c76d9 commit 30e94e8

8 files changed

Lines changed: 60 additions & 22 deletions

File tree

agents/agents.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func (a *Agent) Plan(ctx context.Context) (*Response, error) {
8989
return nil, fmt.Errorf("failed to parse agent response: %w", err)
9090
}
9191

92-
a.addAssistantMessage(ctx, generated.Result)
92+
if err := a.addAssistantMessage(ctx, generated.Result); err != nil {
93+
return nil, fmt.Errorf("failed to store assistant message: %w", err)
94+
}
9395

9496
if parsed.FinalAnswer != "" {
9597
a.finalAnswer = parsed.FinalAnswer
@@ -112,32 +114,30 @@ func (a *Agent) Plan(ctx context.Context) (*Response, error) {
112114

113115
// Act executes the tool chosen by Plan and adds the result as an observation.
114116
// Always call this after Plan (unless Plan returned Finish=true).
115-
func (a *Agent) Act(ctx context.Context) {
117+
func (a *Agent) Act(ctx context.Context) error {
116118
for _, action := range a.actions {
117-
if !a.handleAction(ctx, action) {
118-
return
119+
if err := a.handleAction(ctx, action); err != nil {
120+
return err
119121
}
120122
}
121123
a.clearActions()
124+
return nil
122125
}
123126

124-
func (a *Agent) handleAction(ctx context.Context, action Action) bool {
127+
func (a *Agent) handleAction(ctx context.Context, action Action) error {
125128
t, exists := a.tools[action.Tool]
126129
if !exists {
127-
a.addObservationMessage(ctx, "The action "+action.Tool+" doesn't exist.")
128-
return false
130+
return a.addObservationMessage(ctx, "The action "+action.Tool+" doesn't exist.")
129131
}
130132

131133
observation, err := t.Execute(ctx, tools.Input{
132134
Content: action.ToolInput,
133135
})
134136
if err != nil {
135-
a.addObservationMessage(ctx, "Error: "+err.Error())
136-
return false
137+
return a.addObservationMessage(ctx, "Error: "+err.Error())
137138
}
138139

139-
a.addObservationMessage(ctx, observation.Content)
140-
return true
140+
return a.addObservationMessage(ctx, observation.Content)
141141
}
142142

143143
func (a *Agent) clearActions() {

agents/messages.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"github.com/bit8bytes/gogantic/llms"
88
)
99

10-
func (a *Agent) addAssistantMessage(ctx context.Context, content string) {
11-
a.History.Add(ctx, llms.Message{
12-
Role: roles.Assistent,
10+
func (a *Agent) addAssistantMessage(ctx context.Context, content string) error {
11+
return a.History.Add(ctx, llms.Message{
12+
Role: roles.Assistant,
1313
Content: content,
1414
})
1515
}
1616

17-
func (a *Agent) addObservationMessage(ctx context.Context, observation string) {
18-
a.History.Add(ctx, llms.Message{
17+
func (a *Agent) addObservationMessage(ctx context.Context, observation string) error {
18+
return a.History.Add(ctx, llms.Message{
1919
Role: roles.System,
2020
Content: "Observation: " + observation,
2121
})

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/bit8bytes/gogantic
22

33
go 1.25.7
44

5+
require modernc.org/sqlite v1.46.1
6+
57
require (
68
github.com/dustin/go-humanize v1.0.1 // indirect
79
github.com/google/uuid v1.6.0 // indirect
@@ -13,5 +15,4 @@ require (
1315
modernc.org/libc v1.67.6 // indirect
1416
modernc.org/mathutil v1.7.1 // indirect
1517
modernc.org/memory v1.11.0 // indirect
16-
modernc.org/sqlite v1.46.1 // indirect
1718
)

go.sum

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
22
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
3+
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
4+
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
35
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
46
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7+
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
8+
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
59
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
610
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
711
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
@@ -10,14 +14,40 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
1014
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
1115
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
1216
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
17+
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
18+
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
19+
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
20+
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
1321
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1422
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
1523
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
24+
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
25+
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
26+
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
27+
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
28+
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
29+
modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM=
30+
modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA=
31+
modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
32+
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
33+
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
34+
modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE=
35+
modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
36+
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
37+
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
1638
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
1739
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
1840
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
1941
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
2042
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
2143
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
44+
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
45+
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
46+
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
47+
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
2248
modernc.org/sqlite v1.46.1 h1:eFJ2ShBLIEnUWlLy12raN0Z1plqmFX9Qe3rjQTKt6sU=
2349
modernc.org/sqlite v1.46.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
50+
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
51+
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
52+
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
53+
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

inputs/roles/roles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Role string
55
const (
66
System Role = "system"
77
User Role = "user"
8-
Assistent Role = "assistent"
8+
Assistant Role = "assistant"
99
)
1010

1111
func (r Role) String() string {

llms/ollama/ollama.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ func (oc *client) StreamContent(ctx context.Context, messages []llms.Message, ha
112112
}
113113
req.Header.Set("Content-Type", "application/json")
114114

115-
client := &http.Client{}
115+
client := &http.Client{
116+
Timeout: 240 * time.Second,
117+
}
116118
resp, err := client.Do(req)
117119
if err != nil {
118120
return fmt.Errorf("error sending request: %w", err)

pipes/pipes.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package pipes
44

55
import (
66
"context"
7-
"log/slog"
7+
"errors"
88

99
"github.com/bit8bytes/gogantic/llms"
1010
)
@@ -25,7 +25,6 @@ type Pipe[T any] struct {
2525
messages []llms.Message
2626
model llm
2727
parser parser[T]
28-
logger *slog.Logger
2928
}
3029

3130
// New creates a new Pipe with the given messages, model, and parser.
@@ -41,6 +40,10 @@ func New[T any](messages []llms.Message, model llm, parser parser[T]) *Pipe[T] {
4140
// message, generating a response from the model, and parsing the result into
4241
// a value of type T.
4342
func (pipe *Pipe[T]) Invoke(ctx context.Context) (*T, error) {
43+
if len(pipe.messages) == 0 {
44+
return nil, errors.New("pipe has no messages")
45+
}
46+
4447
instructions := pipe.parser.Instructions()
4548
pipe.messages[0].Content += " " + instructions
4649

runner/runner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ RUN:
5151
return nil
5252
}
5353

54-
r.agent.Act(ctx)
54+
if err := r.agent.Act(ctx); err != nil {
55+
return fmt.Errorf("action failed: %w", err)
56+
}
5557
}
5658
}
5759
return fmt.Errorf("no final answer available")

0 commit comments

Comments
 (0)