Skip to content

Commit c8386a5

Browse files
committed
Updated
1 parent a709077 commit c8386a5

File tree

6 files changed

+31
-76
lines changed

6 files changed

+31
-76
lines changed

cmd/agent/generate.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ func (cmd *GenerateCmd) Run(globals *Globals) error {
3737

3838
// Create a session
3939
session := model.Context(agent.WithStream(!cmd.NoStream))
40-
if err != nil {
41-
return err
42-
}
4340

4441
// Continue looping until end of input
4542
for {
@@ -57,14 +54,10 @@ func (cmd *GenerateCmd) Run(globals *Globals) error {
5754
}
5855

5956
// Feed input into the model
60-
response, err := session.FromUser(ctx, input)
61-
if err != nil {
57+
if err := session.FromUser(ctx, input); err != nil {
6258
return err
6359
}
64-
fmt.Println(response.Text())
65-
66-
// Update session
67-
session = response
60+
fmt.Println(session.Text())
6861
}
6962
})
7063
}

cmd/agent/models.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
// Packages
@@ -48,9 +49,18 @@ func (*ListAgentsCmd) Run(globals *Globals) error {
4849
if !ok {
4950
return fmt.Errorf("No agents found")
5051
}
52+
53+
var agents []string
5154
for _, agent := range agent.Agents() {
52-
fmt.Println(agent)
55+
agents = append(agents, agent.Name())
56+
}
57+
58+
data, err := json.MarshalIndent(agents, "", " ")
59+
if err != nil {
60+
return err
5361
}
62+
fmt.Println(string(data))
63+
5464
return nil
5565
})
5666
}

pkg/agent/agent.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ func (a *Agent) Agents() []llm.Agent {
6666

6767
// Return a list of tool names
6868
func (a *Agent) Tools() []string {
69-
var keys []string
70-
for k := range a.tools {
71-
keys = append(keys, k)
69+
if a.toolkit == nil {
70+
return nil
71+
}
72+
var result []string
73+
for _, t := range a.toolkit.Tools(a) {
74+
result = append(result, t.Name())
7275
}
73-
return keys
76+
return result
7477
}
7578

7679
// Return a comma-separated list of agent names
@@ -121,7 +124,9 @@ func (a *Agent) ListModels(ctx context.Context, agents ...string) ([]llm.Model,
121124
// If multiple agents are specified, then the first model found is returned.
122125
func (a *Agent) GetModel(ctx context.Context, name string, agents ...string) (llm.Model, error) {
123126
if len(agents) == 0 {
124-
agents = a.Agents()
127+
for _, agent := range a.agents {
128+
agents = append(agents, agent.Name())
129+
}
125130
}
126131

127132
// Ensure all agents are valid
@@ -155,11 +160,6 @@ func (a *Agent) Embedding(context.Context, llm.Model, string, ...llm.Opt) ([]flo
155160
return nil, llm.ErrNotImplemented
156161
}
157162

158-
// Create the result of calling a tool
159-
func (a *Agent) ToolResult(id string, opts ...llm.Opt) llm.Context {
160-
return nil
161-
}
162-
163163
///////////////////////////////////////////////////////////////////////////////
164164
// PRIVATE METHODS
165165

pkg/agent/context.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

pkg/agent/generate.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

pkg/agent/opt.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
llm "github.com/mutablelogic/go-llm"
99
anthropic "github.com/mutablelogic/go-llm/pkg/anthropic"
1010
ollama "github.com/mutablelogic/go-llm/pkg/ollama"
11+
"github.com/mutablelogic/go-llm/pkg/tool"
1112
)
1213

1314
////////////////////////////////////////////////////////////////////////////////
1415
// TYPES
1516

1617
type opt struct {
17-
agents map[string]llm.Agent
18-
tools map[string]llm.Tool
18+
agents map[string]llm.Agent
19+
toolkit *tool.ToolKit
1920

2021
// Translated options for each agent implementation
2122
ollama []llm.Opt
@@ -62,17 +63,12 @@ func WithAnthropic(key string, opts ...client.ClientOpt) llm.Opt {
6263
}
6364
}
6465

65-
// Append tools
66-
func WithTools(tools ...llm.Tool) llm.Opt {
66+
// Append toolkit
67+
func WithToolKit(toolkit *tool.ToolKit) llm.Opt {
6768
return func(o any) error {
68-
for _, tool := range tools {
69-
name := tool.Name()
70-
if _, exists := o.(*opt).tools[name]; exists {
71-
return llm.ErrConflict.Withf("Tool %q already exists", name)
72-
}
73-
o.(*opt).tools[name] = tool
74-
}
75-
// Return success
69+
o.(*opt).toolkit = toolkit
70+
o.(*opt).ollama = append(o.(*opt).ollama, ollama.WithToolKit(toolkit))
71+
o.(*opt).anthropic = append(o.(*opt).anthropic, anthropic.WithToolKit(toolkit))
7672
return nil
7773
}
7874
}

0 commit comments

Comments
 (0)