- token_estimator.go (new): TokenEstimator with ~4 chars/token heuristic,
EstimateText/EstimateMessages methods, TruncateMessages sliding window
that drops oldest messages to fit token budget, BuildContextWindow
entry point that converts conversation messages to LLM format with
token-budgeted truncation (default 4096 tokens)
- copilot_context_service.go: fetch up to 100 messages (was 20), then
apply BuildContextWindow truncation to fit within 4096 token budget;
log how many messages were dropped
Verified: go build + go vet + go test all pass
Semantic search route reaches handler (times out on LLM call without API key,
confirming route + service wiring is correct)
- llm/provider.go: extend ChatMessage with ToolCalls, ToolCallID, Name
fields; add ToolCall + ToolCallFunction structs for parsing LLM
function call responses
- tool_execution_service.go (new): ToolExecutionService that converts
CaptainCustomTool → LLM ToolDefinition, executes HTTP tool calls
(GET/POST/PUT with bearer/basic/api-key auth), and runs the full
tool_call loop (LLM → tool_call → execute → result → LLM → final
answer) with maxIterations safeguard
- captain_conversation_service.go: add toolExecSvc field +
SetToolExecutionService method; use RunToolCallLoop in
generateConversationResponse when tools are available, with graceful
fallback to plain LLM call on error
- bootstrap.go: instantiate ToolExecutionService and inject into
CaptainConversationService
Verified: go build + go vet + go test all pass