style: gofmt
Formatting only (struct field alignment, import ordering) across the files that didn't comply — no semantic changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
2e23216932
commit
724a143f90
15 changed files with 88 additions and 90 deletions
|
|
@ -96,10 +96,10 @@ func TestIntegration_AgentLoop_Generate(t *testing.T) {
|
|||
})
|
||||
|
||||
loop := agent.New(agent.Config{
|
||||
LLM: client,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
Sandbox: &mockSandbox{},
|
||||
LLM: client,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
Sandbox: &mockSandbox{},
|
||||
MaxIters: 3,
|
||||
})
|
||||
|
||||
|
|
@ -124,9 +124,9 @@ func TestIntegration_AgentLoop_Stream(t *testing.T) {
|
|||
}
|
||||
|
||||
loop := agent.New(agent.Config{
|
||||
LLM: client,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: tools.NewRegistry(),
|
||||
LLM: client,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: tools.NewRegistry(),
|
||||
MaxIters: 3,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ func (m *mockLLM) Stream(ctx context.Context, req llm.CompletionRequest) iter.Se
|
|||
return m.streamFunc(ctx, req)
|
||||
}
|
||||
|
||||
func (m *mockLLM) Name() string { return "mock" }
|
||||
func (m *mockLLM) Capabilities() llm.ProviderCapabilities { return llm.ProviderCapabilities{} }
|
||||
func (m *mockLLM) Name() string { return "mock" }
|
||||
func (m *mockLLM) Capabilities() llm.ProviderCapabilities { return llm.ProviderCapabilities{} }
|
||||
|
||||
type mockSandbox struct {
|
||||
validateFunc func(tool tools.Tool, call llm.ToolCall) error
|
||||
|
|
@ -71,9 +71,9 @@ func TestNew_CustomMaxIters(t *testing.T) {
|
|||
}
|
||||
|
||||
loop := New(Config{
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: tools.NewRegistry(),
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: tools.NewRegistry(),
|
||||
MaxIters: 10,
|
||||
})
|
||||
|
||||
|
|
@ -373,9 +373,9 @@ func TestRun_MaxIterations(t *testing.T) {
|
|||
})
|
||||
|
||||
loop := New(Config{
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
MaxIters: 3,
|
||||
})
|
||||
|
||||
|
|
@ -706,9 +706,9 @@ func TestRun_Stream_MaxIterations(t *testing.T) {
|
|||
})
|
||||
|
||||
loop := New(Config{
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
LLM: mockClient,
|
||||
Persona: persona.DefaultPersona(),
|
||||
Tools: registry,
|
||||
MaxIters: 1,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -7,34 +7,34 @@ import (
|
|||
|
||||
// ProviderConfig holds provider-specific settings.
|
||||
type ProviderConfig struct {
|
||||
Type string `yaml:"type"`
|
||||
Model string `yaml:"model"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
BaseURL string `yaml:"base_url,omitempty"`
|
||||
MaxTokens int `yaml:"max_tokens,omitempty"`
|
||||
Type string `yaml:"type"`
|
||||
Model string `yaml:"model"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
BaseURL string `yaml:"base_url,omitempty"`
|
||||
MaxTokens int `yaml:"max_tokens,omitempty"`
|
||||
Temperature float32 `yaml:"temperature,omitempty"`
|
||||
}
|
||||
|
||||
// ToolPolicy controls which tools are available and their permissions.
|
||||
type ToolPolicy struct {
|
||||
DefaultPermission string `yaml:"default_permission"`
|
||||
AllowList []string `yaml:"allow_list,omitempty"`
|
||||
DenyList []string `yaml:"deny_list,omitempty"`
|
||||
DefaultPermission string `yaml:"default_permission"`
|
||||
AllowList []string `yaml:"allow_list,omitempty"`
|
||||
DenyList []string `yaml:"deny_list,omitempty"`
|
||||
}
|
||||
|
||||
// LoggingConfig controls logging output.
|
||||
type LoggingConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
Format string `yaml:"format"`
|
||||
Output string `yaml:"output"`
|
||||
Level string `yaml:"level"`
|
||||
Format string `yaml:"format"`
|
||||
Output string `yaml:"output"`
|
||||
}
|
||||
|
||||
// Config is the top-level configuration for the agent.
|
||||
type Config struct {
|
||||
Model string `yaml:"model"`
|
||||
Provider ProviderConfig `yaml:"provider"`
|
||||
Tools ToolPolicy `yaml:"tools"`
|
||||
Logging LoggingConfig `yaml:"logging"`
|
||||
Model string `yaml:"model"`
|
||||
Provider ProviderConfig `yaml:"provider"`
|
||||
Tools ToolPolicy `yaml:"tools"`
|
||||
Logging LoggingConfig `yaml:"logging"`
|
||||
}
|
||||
|
||||
// Loader is responsible for loading configuration from various sources.
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
// MockLLMClient is a deterministic implementation of llm.LLMClient for testing.
|
||||
type MockLLMClient struct {
|
||||
GenerateFunc func(ctx context.Context, req llm.CompletionRequest) (llm.CompletionResponse, error)
|
||||
StreamFunc func(ctx context.Context, req llm.CompletionRequest) iter.Seq2[llm.StreamChunk, error]
|
||||
NameFunc func() string
|
||||
GenerateFunc func(ctx context.Context, req llm.CompletionRequest) (llm.CompletionResponse, error)
|
||||
StreamFunc func(ctx context.Context, req llm.CompletionRequest) iter.Seq2[llm.StreamChunk, error]
|
||||
NameFunc func() string
|
||||
CapabilitiesFunc func() llm.ProviderCapabilities
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ func TestMockLLMClient_MatchResponse(t *testing.T) {
|
|||
client := NewWithMatch([]MatchResponse{
|
||||
{Match: "hello", Response: "hi there!"},
|
||||
{Match: "world", Response: "earth"},
|
||||
{Match: "*", Response: "default"},
|
||||
{Match: "*", Response: "default"},
|
||||
})
|
||||
|
||||
resp, _ := client.Generate(context.Background(), llm.CompletionRequest{
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ func TestClient_Generate(t *testing.T) {
|
|||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(llamaChatResponse{
|
||||
ID: "llama-123",
|
||||
Model: "llama3",
|
||||
ID: "llama-123",
|
||||
Model: "llama3",
|
||||
Choices: []llamaChoice{
|
||||
{
|
||||
Index: 0,
|
||||
|
|
@ -189,8 +189,8 @@ func TestClient_Generate_ToolCall(t *testing.T) {
|
|||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(llamaChatResponse{
|
||||
ID: "llama-tool-1",
|
||||
Model: "llama3",
|
||||
ID: "llama-tool-1",
|
||||
Model: "llama3",
|
||||
Choices: []llamaChoice{
|
||||
{
|
||||
Index: 0,
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ func TestClient_Generate(t *testing.T) {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(openaiChatResponse{
|
||||
ID: "test-123",
|
||||
Model: "gpt-4",
|
||||
ID: "test-123",
|
||||
Model: "gpt-4",
|
||||
Choices: []openaiChoice{
|
||||
{
|
||||
Index: 0,
|
||||
|
|
@ -55,8 +55,8 @@ func TestClient_Generate(t *testing.T) {
|
|||
defer server.Close()
|
||||
|
||||
client, err := New(Config{
|
||||
APIKey: "test-key",
|
||||
BaseURL: server.URL,
|
||||
APIKey: "test-key",
|
||||
BaseURL: server.URL,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
@ -90,8 +90,8 @@ func TestClient_Generate_Error(t *testing.T) {
|
|||
defer server.Close()
|
||||
|
||||
client, err := New(Config{
|
||||
APIKey: "bad-key",
|
||||
BaseURL: server.URL,
|
||||
APIKey: "bad-key",
|
||||
BaseURL: server.URL,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
@ -113,8 +113,8 @@ func TestClient_Stream(t *testing.T) {
|
|||
defer server.Close()
|
||||
|
||||
client, err := New(Config{
|
||||
APIKey: "test-key",
|
||||
BaseURL: server.URL + "/v1",
|
||||
APIKey: "test-key",
|
||||
BaseURL: server.URL + "/v1",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
|
|||
|
|
@ -10,18 +10,18 @@ import (
|
|||
type Role string
|
||||
|
||||
const (
|
||||
RoleSystem Role = "system"
|
||||
RoleUser Role = "user"
|
||||
RoleSystem Role = "system"
|
||||
RoleUser Role = "user"
|
||||
RoleAssistant Role = "assistant"
|
||||
RoleTool Role = "tool"
|
||||
RoleTool Role = "tool"
|
||||
)
|
||||
|
||||
// Message is a single message in a conversation.
|
||||
type Message struct {
|
||||
Role Role `json:"role"`
|
||||
Content string `json:"content"`
|
||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Role Role `json:"role"`
|
||||
Content string `json:"content"`
|
||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
// ToolCalls records the calls an assistant message requested, so the
|
||||
// agent loop can replay them on the next request: without this, the
|
||||
// conversation sent back to the model has tool-result messages with no
|
||||
|
|
@ -50,8 +50,8 @@ type TokenUsage struct {
|
|||
type ToolChoice string
|
||||
|
||||
const (
|
||||
ToolChoiceAuto ToolChoice = "auto"
|
||||
ToolChoiceNone ToolChoice = "none"
|
||||
ToolChoiceAuto ToolChoice = "auto"
|
||||
ToolChoiceNone ToolChoice = "none"
|
||||
ToolChoiceRequired ToolChoice = "required"
|
||||
)
|
||||
|
||||
|
|
@ -73,14 +73,14 @@ func (t *ToolRef) MarshalJSON() ([]byte, error) {
|
|||
|
||||
// CompletionRequest is sent to an LLM provider.
|
||||
type CompletionRequest struct {
|
||||
Model string `json:"model"`
|
||||
Messages []Message `json:"messages"`
|
||||
Tools []json.RawMessage `json:"tools,omitempty"`
|
||||
ToolChoice interface{} `json:"tool_choice,omitempty"` // ToolChoice, ToolRef, or null
|
||||
Temperature *float32 `json:"temperature,omitempty"`
|
||||
MaxTokens *int `json:"max_tokens,omitempty"`
|
||||
Stop []string `json:"stop,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
Model string `json:"model"`
|
||||
Messages []Message `json:"messages"`
|
||||
Tools []json.RawMessage `json:"tools,omitempty"`
|
||||
ToolChoice interface{} `json:"tool_choice,omitempty"` // ToolChoice, ToolRef, or null
|
||||
Temperature *float32 `json:"temperature,omitempty"`
|
||||
MaxTokens *int `json:"max_tokens,omitempty"`
|
||||
Stop []string `json:"stop,omitempty"`
|
||||
Metadata map[string]string `json:"metadata,omitempty"`
|
||||
ChatTemplateKwargs map[string]any `json:"chat_template_kwargs,omitempty"` // model-specific chat template params, e.g. Qwen enable_thinking
|
||||
}
|
||||
|
||||
|
|
@ -98,9 +98,9 @@ type CompletionResponse struct {
|
|||
// StopReason values.
|
||||
const (
|
||||
StopReasonEndTurn = "end_turn"
|
||||
StopReasonToolUse = "tool_use"
|
||||
StopReasonToolUse = "tool_use"
|
||||
StopReasonMaxTokens = "max_tokens"
|
||||
StopReasonStopSeq = "stop_sequence"
|
||||
StopReasonStopSeq = "stop_sequence"
|
||||
)
|
||||
|
||||
// ToolCall represents a function invocation requested by the model.
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func TestToolCall_JSON(t *testing.T) {
|
|||
|
||||
func TestStreamChunk_JSON(t *testing.T) {
|
||||
chunk := StreamChunk{
|
||||
Delta: "hello",
|
||||
Delta: "hello",
|
||||
ToolCalls: []ToolCall{},
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,5 @@ func TestStreamChunk_JSON(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func float32Ptr(f float32) *float32 { return &f }
|
||||
func float32Ptr(f float32) *float32 { return &f }
|
||||
func intPtr(i int) *int { return &i }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type Persona struct {
|
|||
Style string
|
||||
Language string
|
||||
Constraints []string
|
||||
FewShot []llm.Message
|
||||
FewShot []llm.Message
|
||||
}
|
||||
|
||||
// Loader loads personas from files.
|
||||
|
|
|
|||
|
|
@ -224,13 +224,13 @@ func stringifyMap(m map[string]interface{}) map[string]string {
|
|||
|
||||
// chromaQueryResponse represents the structure of a ChromaDB query response.
|
||||
type chromaQueryResponse struct {
|
||||
Names []string `json:"names"`
|
||||
Names []string `json:"names"`
|
||||
Results []chromaQueryResults `json:"results"`
|
||||
}
|
||||
|
||||
type chromaQueryResults struct {
|
||||
IDs [][]string `json:"ids"`
|
||||
Documents [][]string `json:"documents"`
|
||||
Distances [][]float64 `json:"distances"`
|
||||
IDs [][]string `json:"ids"`
|
||||
Documents [][]string `json:"documents"`
|
||||
Distances [][]float64 `json:"distances"`
|
||||
Metadatas [][]map[string]interface{} `json:"metadatas"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func TestBackend_Search(t *testing.T) {
|
|||
meta := []map[string]interface{}{{"key": "value"}}
|
||||
metaNested := [][]map[string]interface{}{meta}
|
||||
mockResponse := map[string]interface{}{
|
||||
"names": []string{"rony-memory"},
|
||||
"names": []string{"rony-memory"},
|
||||
"results": []map[string]interface{}{
|
||||
{
|
||||
"ids": [][]string{{"test-id"}},
|
||||
|
|
|
|||
|
|
@ -193,9 +193,9 @@ func TestMemory_Search_EmbeddingErrorFallsBackToLexicalSearch(t *testing.T) {
|
|||
|
||||
// mockBackend implements chroma.Backend for testing.
|
||||
type mockBackend struct {
|
||||
upsertFunc func(ctx context.Context, id string, vector []float32, content string, metadata map[string]string) error
|
||||
searchFunc func(ctx context.Context, query string, queryVector []float32, topK int) ([]rag.SearchResult, error)
|
||||
forgetAllFunc func(ctx context.Context) error
|
||||
upsertFunc func(ctx context.Context, id string, vector []float32, content string, metadata map[string]string) error
|
||||
searchFunc func(ctx context.Context, query string, queryVector []float32, topK int) ([]rag.SearchResult, error)
|
||||
forgetAllFunc func(ctx context.Context) error
|
||||
}
|
||||
|
||||
func (m *mockBackend) Upsert(ctx context.Context, id string, vector []float32, content string, metadata map[string]string) error {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
// registry is the default implementation of Registry.
|
||||
type registry struct {
|
||||
mu sync.RWMutex
|
||||
tools map[string]Tool
|
||||
order []string
|
||||
mu sync.RWMutex
|
||||
tools map[string]Tool
|
||||
order []string
|
||||
}
|
||||
|
||||
// NewRegistry returns a new empty registry.
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ type ToolHandler func(ctx context.Context, args json.RawMessage) (ToolResult, er
|
|||
|
||||
// ToolResult is returned by a ToolHandler.
|
||||
type ToolResult struct {
|
||||
Content string
|
||||
IsError bool
|
||||
Metadata map[string]string
|
||||
Artifacts []Artifact
|
||||
Content string
|
||||
IsError bool
|
||||
Metadata map[string]string
|
||||
Artifacts []Artifact
|
||||
}
|
||||
|
||||
// Artifact represents a file or data artifact produced by a tool.
|
||||
|
|
@ -60,8 +60,8 @@ type Artifact struct {
|
|||
|
||||
// ToolExample provides few-shot examples for the LLM to improve tool usage.
|
||||
type ToolExample struct {
|
||||
Input map[string]interface{}
|
||||
Output string
|
||||
Input map[string]interface{}
|
||||
Output string
|
||||
}
|
||||
|
||||
// Registry manages tool registration and lookup.
|
||||
|
|
|
|||
Loading…
Reference in a new issue