package main
import (
"context"
"fmt"
"log"
"github.com/bytedance/sonic"
"github.com/curaious/uno/internal/utils"
"github.com/curaious/uno/pkg/agent-framework/core"
"github.com/curaious/uno/pkg/agent-framework/tools"
"github.com/curaious/uno/pkg/gateway"
"github.com/curaious/uno/pkg/llm"
"github.com/curaious/uno/pkg/llm/responses"
"github.com/curaious/uno/pkg/sdk"
)
func main() {
// Initialize SDK client
client, err := sdk.New(&sdk.ClientOptions{
LLMConfigs: sdk.NewInMemoryConfigStore([]*gateway.ProviderConfig{
{
ProviderName: llm.ProviderNameOpenAI,
BaseURL: "",
CustomHeaders: nil,
ApiKeys: []*gateway.APIKeyConfig{
{
Name: "Key 1",
APIKey: "",
},
},
},
}),
})
if err != nil {
log.Fatal(err)
}
// Create LLM model
model := client.NewLLM(sdk.LLMOptions{
Provider: llm.ProviderNameOpenAI,
Model: "gpt-4o-mini",
})
// Create a specialized agent that will act as a tool
subAgent := client.NewAgent(&sdk.AgentOptions{
Name: "Hello world agent",
Instruction: client.Prompt("You are helpful assistant."),
LLM: model,
})
// Wrap the agent as a tool
agentTool := tools.NewAgentTool(&responses.ToolUnion{
OfFunction: &responses.FunctionTool{
Name: "get_user_name",
Description: utils.Ptr("Returns the user's name"),
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"user_id": map[string]any{
"type": "string",
"description": "The user ID to look up",
},
},
"required": []string{"user_id"},
},
},
}, subAgent)
// Create the main agent that uses the agent tool
agent := client.NewAgent(&sdk.AgentOptions{
Name: "Hello world agent",
Instruction: client.Prompt("You are helpful assistant."),
LLM: model,
Tools: []core.Tool{agentTool},
})
// Execute the main agent
out, err := agent.Execute(context.Background(), &agents.AgentInput{
Messages: []responses.InputMessageUnion{
responses.UserMessage("Hello!"),
},
})
if err != nil {
log.Fatal(err)
}
b, _ := sonic.Marshal(out)
fmt.Println(string(b))
}