Enha: agentclient log
This commit is contained in:
@@ -26,6 +26,10 @@ func NewAgentClient(cfg *config.Config, log slog.Logger, gt func() string) *Agen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ag *AgentClient) Log() *slog.Logger {
|
||||||
|
return &ag.log
|
||||||
|
}
|
||||||
|
|
||||||
func (ag *AgentClient) FormMsg(sysprompt, msg string) (io.Reader, error) {
|
func (ag *AgentClient) FormMsg(sysprompt, msg string) (io.Reader, error) {
|
||||||
agentConvo := []models.RoleMsg{
|
agentConvo := []models.RoleMsg{
|
||||||
{Role: "system", Content: sysprompt},
|
{Role: "system", Content: sysprompt},
|
||||||
|
|||||||
@@ -2,19 +2,17 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// WebAgentB is a simple agent that applies formatting functions
|
// WebAgentB is a simple agent that applies formatting functions
|
||||||
type WebAgentB struct {
|
type WebAgentB struct {
|
||||||
*AgentClient
|
*AgentClient
|
||||||
sysprompt string
|
sysprompt string
|
||||||
log slog.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWebAgentB creates a WebAgentB that uses the given formatting function
|
// NewWebAgentB creates a WebAgentB that uses the given formatting function
|
||||||
func NewWebAgentB(sysprompt string) *WebAgentB {
|
func NewWebAgentB(client *AgentClient, sysprompt string) *WebAgentB {
|
||||||
return &WebAgentB{sysprompt: sysprompt}
|
return &WebAgentB{AgentClient: client, sysprompt: sysprompt}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process applies the formatting function to raw output
|
// Process applies the formatting function to raw output
|
||||||
@@ -22,12 +20,12 @@ func (a *WebAgentB) Process(args map[string]string, rawOutput []byte) []byte {
|
|||||||
msg, err := a.FormMsg(a.sysprompt,
|
msg, err := a.FormMsg(a.sysprompt,
|
||||||
fmt.Sprintf("request:\n%+v\ntool response:\n%v", args, string(rawOutput)))
|
fmt.Sprintf("request:\n%+v\ntool response:\n%v", args, string(rawOutput)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to process the request", "error", err)
|
a.Log().Error("failed to process the request", "error", err)
|
||||||
return []byte("failed to process the request; err: " + err.Error())
|
return []byte("failed to process the request; err: " + err.Error())
|
||||||
}
|
}
|
||||||
resp, err := a.LLMRequest(msg)
|
resp, err := a.LLMRequest(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to process the request", "error", err)
|
a.Log().Error("failed to process the request", "error", err)
|
||||||
return []byte("failed to process the request; err: " + err.Error())
|
return []byte("failed to process the request; err: " + err.Error())
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
|
|||||||
Reference in New Issue
Block a user