Documentation Index
Fetch the complete documentation index at: https://hastekit.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
You can use an agent as a tool that another agent can call. This enables hierarchical agent architectures where specialized agents handle specific tasks, and a parent agent orchestrates them by calling these agent tools as needed.
To create an agent tool, you need to:
- Create a specialized agent that will act as the tool
- Wrap it using
tools.NewAgentTool with a tool definition
import (
hastekit "github.com/hastekit/hastekit-sdk-go"
"github.com/hastekit/hastekit-sdk-go/pkg/agents/tools"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm/responses"
"github.com/hastekit/hastekit-sdk-go/pkg/utils"
)
// Create a specialized agent
subAgent := client.NewAgent(&hastekit.AgentOptions{
Name: "User lookup agent",
Instruction: client.Prompt("You are a helpful assistant that looks up user information."),
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, tools.SubAgentContextModeNone)
Parameters
toolUnion: A *responses.ToolUnion that defines the tool’s interface (name, description, parameters)
agent: The agent instance that will be executed when the tool is called
contextMode: Context mode for the agent tool.
SubAgentContextModeNone - Each invocation of the agent tool starts with an empty context.
SubAgentContextModeIsolated - Each invocation of the agent tool starts with context of all the previous invocation.
When the tool is called, the agent receives the tool’s arguments as input and returns its output as the tool’s result.
Once created, you can use the agent tool in another agent’s tools list:
// Create a parent agent that uses the agent tool
agent := client.NewAgent(&hastekit.AgentOptions{
Name: "Main agent",
Instruction: client.Prompt("You are a helpful assistant. Use the get_user_name tool when needed."),
LLM: model,
Tools: []agents.Tool{agentTool},
})
Complete Example
Here’s a complete example demonstrating an agent using another agent as a tool:
package main
import (
"context"
"fmt"
"log"
"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/tools"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm/responses"
"github.com/hastekit/hastekit-sdk-go/pkg/utils"
)
func main() {
// Initialize SDK client
client, err := hastekit.New(&hastekit.ClientOptions{
ProviderConfigs: []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(hastekit.LLMOptions{
Provider: llm.ProviderNameOpenAI,
Model: "gpt-4o-mini",
})
// Create a specialized agent that will act as a tool
subAgent := client.NewAgent(&hastekit.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, tools.SubAgentContextModeNone)
// Create the main agent that uses the agent tool
agent := client.NewAgent(&hastekit.AgentOptions{
Name: "Hello world agent",
Instruction: client.Prompt("You are helpful assistant."),
LLM: model,
Tools: []agents.Tool{agentTool},
})
// Execute the main agent
handle, err := agent.Execute(context.Background(), &agents.AgentInput{
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))
}