mirror of
https://github.com/hanzoai/agents.git
synced 2026-10-30 18:48:36 +00:00
Transforms hanzoai/agents from a marketplace config repo into a full agent orchestration platform by merging the AgentField infrastructure: - Go control plane (K8s-like agent orchestration, service mesh, DAG workflows) - Python SDK (FastAPI-based agent framework, LiteLLM, memory, DID/VC) - TypeScript SDK (@hanzo/agents - Vercel AI SDK, MCP, workflows) - Go SDK (idiomatic agent builder + client) - React 19 embedded dashboard (XyFlow DAGs, Recharts, Radix UI) - Docker/K8s/Helm deployment configs - Examples: hello world, deep research, RAG, simulation, benchmarks - Functional test suite across Python/Go/TypeScript All references rebranded: AgentField → Hanzo Agents - Module: github.com/hanzoai/agents/control-plane - Python: hanzo_agents - TypeScript: @hanzo/agents - Go: github.com/hanzoai/agents/sdk/go - Env vars: HANZO_AGENTS_* - Config: hanzo-agents.yaml Previous marketplace configs moved to config/ directory.
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package ai
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Response represents the API response from OpenAI/OpenRouter.
|
|
type Response struct {
|
|
ID string `json:"id"`
|
|
Object string `json:"object"`
|
|
Created int64 `json:"created"`
|
|
Model string `json:"model"`
|
|
Choices []Choice `json:"choices"`
|
|
Usage *Usage `json:"usage,omitempty"`
|
|
}
|
|
|
|
// Choice represents a completion choice.
|
|
type Choice struct {
|
|
Index int `json:"index"`
|
|
Message Message `json:"message"`
|
|
FinishReason string `json:"finish_reason"`
|
|
}
|
|
|
|
// Usage represents token usage information.
|
|
type Usage struct {
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
TotalTokens int `json:"total_tokens"`
|
|
}
|
|
|
|
// StreamChunk represents a streaming response chunk.
|
|
type StreamChunk struct {
|
|
ID string `json:"id"`
|
|
Object string `json:"object"`
|
|
Created int64 `json:"created"`
|
|
Model string `json:"model"`
|
|
Choices []StreamDelta `json:"choices"`
|
|
}
|
|
|
|
// StreamDelta represents a delta in a streaming response.
|
|
type StreamDelta struct {
|
|
Index int `json:"index"`
|
|
Delta MessageDelta `json:"delta"`
|
|
FinishReason *string `json:"finish_reason"`
|
|
}
|
|
|
|
// MessageDelta represents the incremental message content.
|
|
type MessageDelta struct {
|
|
Role string `json:"role,omitempty"`
|
|
Content string `json:"content,omitempty"`
|
|
}
|
|
|
|
// ErrorResponse represents an error from the API.
|
|
type ErrorResponse struct {
|
|
Error ErrorDetail `json:"error"`
|
|
}
|
|
|
|
// ErrorDetail contains error information.
|
|
type ErrorDetail struct {
|
|
Message string `json:"message"`
|
|
Type string `json:"type"`
|
|
Code string `json:"code,omitempty"`
|
|
}
|
|
|
|
// Text returns the text content from the first choice.
|
|
func (r *Response) Text() string {
|
|
if len(r.Choices) == 0 {
|
|
return ""
|
|
}
|
|
return r.Choices[0].Message.Content
|
|
}
|
|
|
|
// JSON parses the response content as JSON into the provided destination.
|
|
func (r *Response) JSON(dest interface{}) error {
|
|
content := r.Text()
|
|
if content == "" {
|
|
return fmt.Errorf("empty response content")
|
|
}
|
|
return json.Unmarshal([]byte(content), dest)
|
|
}
|
|
|
|
// Into is an alias for JSON for ergonomic usage.
|
|
func (r *Response) Into(dest interface{}) error {
|
|
return r.JSON(dest)
|
|
}
|