package main
import (
"context"
"fmt"
"log"
"os"
"github.com/bytedance/sonic"
hastekit "github.com/hastekit/hastekit-sdk-go"
"github.com/hastekit/hastekit-sdk-go/pkg/agents"
"github.com/hastekit/hastekit-sdk-go/pkg/agents/history"
"github.com/hastekit/hastekit-sdk-go/pkg/agents/tools"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm/responses"
)
func main() {
// Initialize LLM client
client := hastekit.NewLLMClient([]hastekit.ProviderConfig{
{
ProviderName: hastekit.ProviderOpenAI,
ApiKeys: []*hastekit.APIKeyConfig{
{
Name: "Key 1",
APIKey: os.Getenv("OPENAI_API_KEY"),
},
},
},
})
// Bind a model
model := client.Model("OpenAI/gpt-4o-mini")
// Create a specialized agent that will act as a tool
subAgent := hastekit.NewAgent(&hastekit.AgentConfig{
Name: "Hello world agent",
Instruction: hastekit.NewPrompt("You are helpful assistant."),
LLM: model,
})
// Wrap the agent as a tool
agentTool := tools.NewAgentTool("get_user_name", "Returns the user's name", subAgent, tools.SubAgentContextModeNone)
// Create the main agent that uses the agent tool
agent := hastekit.NewAgent(&hastekit.AgentConfig{
Name: "Hello world agent",
Instruction: hastekit.NewPrompt("You are helpful assistant."),
LLM: model,
Tools: []hastekit.Tool{agentTool},
})
// Execute the main agent
handle, err := agent.Execute(context.Background(), &agents.AgentInput{
Message: history.Message{
Messages: []responses.InputMessageUnion{
responses.UserMessage("Hello!"),
},
},
})
if err != nil {
log.Fatal(err)
}
out, err := handle.Result()
if err != nil {
log.Fatal(err)
}
b, _ := sonic.Marshal(out)
fmt.Println(string(b))
}