feat(agent): connect agents to real BOC data
BOC CI/CD / Test (push) Failing after 17s
BOC CI/CD / Security Scan (push) Has been skipped
BOC CI/CD / Build & Push (push) Has been skipped
BOC CI/CD / Deploy to Staging (push) Has been skipped
BOC CI/CD / Deploy to Production (push) Has been skipped

- Add AgentDataProvider with real DB queries for finance, CRM, sales, HR
- Inject live data into Anthropic prompts for context-aware responses
- Reuse existing ledgerDB connection for agent data access
- Agents now respond with actual numbers from the system
This commit is contained in:
Bernt
2026-08-12 09:24:47 +00:00
parent 0124fc0186
commit f259610f8c
5 changed files with 445 additions and 5 deletions
+17 -2
View File
@@ -2,6 +2,7 @@ package handlers
import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io"
@@ -36,10 +37,11 @@ type AgentChatResponse struct {
type AgentOrchestrator struct {
anthropicKey string
apiEndpoint string
dataProvider *AgentDataProvider
}
// NewAgentOrchestrator creates a new agent orchestrator
func NewAgentOrchestrator() *AgentOrchestrator {
func NewAgentOrchestrator(db, ledgerDB *sql.DB) *AgentOrchestrator {
key := os.Getenv("ANTHROPIC_API_KEY")
if key == "" {
log.Warn().Msg("ANTHROPIC_API_KEY not set, agent will use mock responses")
@@ -48,6 +50,7 @@ func NewAgentOrchestrator() *AgentOrchestrator {
return &AgentOrchestrator{
anthropicKey: key,
apiEndpoint: "https://api.anthropic.com/v1/messages",
dataProvider: NewAgentDataProvider(db, ledgerDB),
}
}
@@ -81,8 +84,20 @@ func (o *AgentOrchestrator) HandleAgentChat(w http.ResponseWriter, r *http.Reque
return
}
// Hämta real-time data för agenten
dataContext := ""
if o.dataProvider != nil {
dataContext = o.dataProvider.FormatDataForPrompt(req.Rum)
}
// Bygg enhanced prompt med data
enhancedPrompt := req.SystemPrompt
if dataContext != "" {
enhancedPrompt = req.SystemPrompt + dataContext
}
// Call Anthropic API
svar, err := o.callAnthropic(req.SystemPrompt, req.Meddelanden)
svar, err := o.callAnthropic(enhancedPrompt, req.Meddelanden)
if err != nil {
log.Error().Err(err).Str("rum", req.Rum).Msg("Agent chat failed")
// Fallback to mock