From a06cfd995f05782854844e51a71a656f70274f64 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Thu, 18 Dec 2025 11:53:07 +0300 Subject: Feat: add agent entity --- agent/agent.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 agent/agent.go (limited to 'agent/agent.go') diff --git a/agent/agent.go b/agent/agent.go new file mode 100644 index 0000000..30e30e3 --- /dev/null +++ b/agent/agent.go @@ -0,0 +1,60 @@ +package agent + +// Agent defines an interface for processing tool outputs. +// An Agent can clean, summarize, or otherwise transform raw tool outputs +// before they are presented to the main LLM. +type Agent interface { + // Process takes the original tool arguments and the raw output from the tool, + // and returns a cleaned/summarized version suitable for the main LLM context. + Process(args map[string]string, rawOutput []byte) []byte +} + +// registry holds mapping from tool names to agents. +var registry = make(map[string]Agent) + +// Register adds an agent for a specific tool name. +// If an agent already exists for the tool, it will be replaced. +func Register(toolName string, a Agent) { + registry[toolName] = a +} + +// Get returns the agent for a tool name, or nil if none is registered. +func Get(toolName string) Agent { + return registry[toolName] +} + +// FormatterAgent is a simple agent that applies formatting functions. +type FormatterAgent struct { + formatFunc func([]byte) (string, error) +} + +// NewFormatterAgent creates a FormatterAgent that uses the given formatting function. +func NewFormatterAgent(formatFunc func([]byte) (string, error)) *FormatterAgent { + return &FormatterAgent{formatFunc: formatFunc} +} + +// Process applies the formatting function to raw output. +func (a *FormatterAgent) Process(args map[string]string, rawOutput []byte) []byte { + if a.formatFunc == nil { + return rawOutput + } + formatted, err := a.formatFunc(rawOutput) + if err != nil { + // On error, return raw output with a warning prefix + return []byte("[formatting failed, showing raw output]\n" + string(rawOutput)) + } + return []byte(formatted) +} + +// DefaultFormatter returns a FormatterAgent that uses the appropriate formatting +// based on tool name. +func DefaultFormatter(toolName string) Agent { + switch toolName { + case "websearch": + return NewFormatterAgent(FormatSearchResults) + case "read_url": + return NewFormatterAgent(FormatWebPageContent) + default: + return nil + } +} \ No newline at end of file -- cgit v1.2.3 From 67ea1aef0dafb9dc6f82e009cc1ecc613f71e520 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 19 Dec 2025 11:06:22 +0300 Subject: Feat: two agent types; WebAgentB impl --- agent/agent.go | 71 +++++++++++++++++++--------------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) (limited to 'agent/agent.go') diff --git a/agent/agent.go b/agent/agent.go index 30e30e3..5ad1ef1 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1,60 +1,35 @@ package agent -// Agent defines an interface for processing tool outputs. -// An Agent can clean, summarize, or otherwise transform raw tool outputs -// before they are presented to the main LLM. -type Agent interface { - // Process takes the original tool arguments and the raw output from the tool, - // and returns a cleaned/summarized version suitable for the main LLM context. - Process(args map[string]string, rawOutput []byte) []byte -} +// I see two types of agents possible: +// ones who do their own tools calls +// ones that works only with the output -// registry holds mapping from tool names to agents. -var registry = make(map[string]Agent) +// A: main chat -> agent (handles everything: tool + processing) +// B: main chat -> tool -> agent (process tool output) -// Register adds an agent for a specific tool name. -// If an agent already exists for the tool, it will be replaced. -func Register(toolName string, a Agent) { - registry[toolName] = a +// AgenterA gets a task "find out weather in london" +// proceeds to make tool calls on its own +type AgenterA interface { + ProcessTask(task string) []byte } -// Get returns the agent for a tool name, or nil if none is registered. -func Get(toolName string) Agent { - return registry[toolName] +// AgenterB defines an interface for processing tool outputs +type AgenterB interface { + // Process takes the original tool arguments and the raw output from the tool, + // and returns a cleaned/summarized version suitable for the main LLM context + Process(args map[string]string, rawOutput []byte) []byte } -// FormatterAgent is a simple agent that applies formatting functions. -type FormatterAgent struct { - formatFunc func([]byte) (string, error) -} +// registry holds mapping from tool names to agents +var RegistryB = make(map[string]AgenterB) +var RegistryA = make(map[AgenterA][]string) -// NewFormatterAgent creates a FormatterAgent that uses the given formatting function. -func NewFormatterAgent(formatFunc func([]byte) (string, error)) *FormatterAgent { - return &FormatterAgent{formatFunc: formatFunc} +// Register adds an agent for a specific tool name +// If an agent already exists for the tool, it will be replaced +func RegisterB(toolName string, a AgenterB) { + RegistryB[toolName] = a } -// Process applies the formatting function to raw output. -func (a *FormatterAgent) Process(args map[string]string, rawOutput []byte) []byte { - if a.formatFunc == nil { - return rawOutput - } - formatted, err := a.formatFunc(rawOutput) - if err != nil { - // On error, return raw output with a warning prefix - return []byte("[formatting failed, showing raw output]\n" + string(rawOutput)) - } - return []byte(formatted) +func RegisterA(toolNames []string, a AgenterA) { + RegistryA[a] = toolNames } - -// DefaultFormatter returns a FormatterAgent that uses the appropriate formatting -// based on tool name. -func DefaultFormatter(toolName string) Agent { - switch toolName { - case "websearch": - return NewFormatterAgent(FormatSearchResults) - case "read_url": - return NewFormatterAgent(FormatWebPageContent) - default: - return nil - } -} \ No newline at end of file -- cgit v1.2.3 From f779f039745f97f08f25967214d07716ce213326 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 19 Dec 2025 15:39:55 +0300 Subject: Enha: agent request builder --- agent/agent.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'agent/agent.go') diff --git a/agent/agent.go b/agent/agent.go index 5ad1ef1..8824ecb 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -33,3 +33,13 @@ func RegisterB(toolName string, a AgenterB) { func RegisterA(toolNames []string, a AgenterA) { RegistryA[a] = toolNames } + +// Get returns the agent registered for the given tool name, or nil if none. +func Get(toolName string) AgenterB { + return RegistryB[toolName] +} + +// Register is a convenience wrapper for RegisterB. +func Register(toolName string, a AgenterB) { + RegisterB(toolName, a) +} -- cgit v1.2.3