package main
import (
"context"
"log"
"os"
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/history/summariser"
"github.com/hastekit/hastekit-sdk-go/pkg/gateway/llm/responses"
)
func main() {
// Configure an LLM client
client := hastekit.NewLLMClient([]hastekit.ProviderConfig{
{
ProviderName: hastekit.ProviderOpenAI,
BaseURL: "",
CustomHeaders: nil,
ApiKeys: []*hastekit.APIKeyConfig{
{
Name: "Key 1",
APIKey: os.Getenv("OPENAI_API_KEY"),
},
},
},
})
// Create main agent LLM
model := client.Model("OpenAI/gpt-4o-mini")
// Create summarizer LLM (can use a cheaper/faster model)
summarizerLLM := client.Model("OpenAI/gpt-4o-mini")
// Create summarizer instruction
summarizerInstruction := hastekit.NewPrompt(
"You are a conversation summarizer. Create concise summaries that preserve important context, decisions, and information needed for future interactions.",
)
// Create LLM summarizer
summarizer := summariser.NewLLMHistorySummarizer(&summariser.LLMHistorySummarizerOptions{
LLM: summarizerLLM,
Instruction: summarizerInstruction,
TokenThreshold: 1000, // Summarize when tokens exceed 1000
KeepRecentCount: 5, // Keep last 5 runs
Parameters: responses.Parameters{},
})
// Create conversation manager with summarizer
p, _ := history.NewFileConversationPersistence("./conversations")
cm := history.NewConversationManager(
p,
history.WithSummarizer(summarizer),
)
// Create agent with history
agent := hastekit.NewAgent(&hastekit.AgentConfig{
Name: "Assistant",
Instruction: hastekit.NewPrompt("You are a helpful assistant."),
LLM: model,
History: cm,
})
// Execute agent (summarization happens automatically when threshold is exceeded)
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)
}
log.Println(out.Output[0].OfOutputMessage.Content[0].OfOutputText.Text)
}