-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathagent.go
75 lines (65 loc) · 3.07 KB
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package swarmgo
import (
"github.com/prathyushnallamothu/swarmgo/llm"
)
// Agent represents an entity with specific attributes and behaviors.
type Agent struct {
Name string // The name of the agent.
Model string // The model identifier.
Provider llm.LLMProvider // The LLM provider to use.
Config *ClientConfig // Provider-specific configuration.
Instructions string // Static instructions for the agent.
InstructionsFunc func(contextVariables map[string]interface{}) string // Function to generate dynamic instructions based on context.
Functions []AgentFunction // A list of functions the agent can perform.
Memory *MemoryStore // Memory store for the agent.
ParallelToolCalls bool // Whether to allow parallel tool calls.
}
// AgentFunction represents a function that can be performed by an agent
type AgentFunction struct {
Name string // The name of the function.
Description string // Description of what the function does.
Parameters map[string]interface{} // Parameters for the function.
Function func(args map[string]interface{}, contextVariables map[string]interface{}) Result // The actual function implementation.
}
// FunctionToDefinition converts an AgentFunction to a llm.Function
func FunctionToDefinition(af AgentFunction) llm.Function {
return llm.Function{
Name: af.Name,
Description: af.Description,
Parameters: af.Parameters,
}
}
// NewAgent creates a new agent with initialized memory store
func NewAgent(name, model string, provider llm.LLMProvider) *Agent {
return &Agent{
Name: name,
Model: model,
Provider: provider,
Memory: NewMemoryStore(100), // Default to 100 short-term memories
}
}
// WithConfig sets the configuration for the agent
func (a *Agent) WithConfig(config *ClientConfig) *Agent {
a.Config = config
return a
}
// WithInstructions sets the static instructions for the agent
func (a *Agent) WithInstructions(instructions string) *Agent {
a.Instructions = instructions
return a
}
// WithInstructionsFunc sets the dynamic instructions function for the agent
func (a *Agent) WithInstructionsFunc(f func(map[string]interface{}) string) *Agent {
a.InstructionsFunc = f
return a
}
// WithFunctions sets the functions available to the agent
func (a *Agent) WithFunctions(functions []AgentFunction) *Agent {
a.Functions = functions
return a
}
// WithParallelToolCalls enables or disables parallel tool calls
func (a *Agent) WithParallelToolCalls(enabled bool) *Agent {
a.ParallelToolCalls = enabled
return a
}