diff --git a/agent/run.go b/agent/run.go index ef52a0d8..b511bc5b 100644 --- a/agent/run.go +++ b/agent/run.go @@ -15,13 +15,15 @@ import ( // RunRequest is the input for the synchronous agent endpoint. type RunRequest struct { - Prompt string `json:"prompt"` - Model string `json:"model"` + Prompt string `json:"prompt"` + Model string `json:"model"` + ContextID string `json:"context_id"` // prior flow ID for follow-ups } // RunResponse is the output of the synchronous agent endpoint. type RunResponse struct { Answer string `json:"answer"` + FlowID string `json:"flow_id,omitempty"` Tools []ToolUsed `json:"tools,omitempty"` Error string `json:"error,omitempty"` } @@ -146,5 +148,23 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { } answer = app.StripLatexDollars(answer) - app.RespondJSON(w, RunResponse{Answer: answer, Tools: toolsUsed}) + + // Save as a flow so it appears in the agent history at /agent. + var steps []FlowStep + for _, tu := range toolsUsed { + steps = append(steps, FlowStep{Tool: tu.Name}) + } + flow := &Flow{ + ID: newFlowID(), + AccountID: acc.ID, + Prompt: req.Prompt, + Steps: steps, + Answer: answer, + Status: "done", + ParentID: req.ContextID, + CreatedAt: time.Now().UTC(), + } + saveFlow(flow) + + app.RespondJSON(w, RunResponse{Answer: answer, FlowID: flow.ID, Tools: toolsUsed}) } diff --git a/home/home.go b/home/home.go index e96285ea..1199b9de 100644 --- a/home/home.go +++ b/home/home.go @@ -544,6 +544,7 @@ const consoleScript = `