[Phase 3] Agent learning loop — record decisions + outcomes via memory service #18

Open
opened 2026-09-09 01:05:07 +00:00 by poimen · 0 comments
Member

Goal

After each task execution, agent records its decision, reasoning, and outcome to memory service. Before each task, agent queries past decisions for context.

Depends On

  • Memory service: agent entity endpoints (poimen-memory Phase 3.2-3.4)
  • This repo: synthesis activities registered (#14)

Workflow: AgentLearningWorkflow

Input: { tool, task, context }

1. QueryPastDecisions — GET /memory/query?entity_type=agent_decision&tool=X
2. ExecuteTask — run actual task workflow (orchestrator/routing)
3. RecordDecision — POST /memory/ingest (entity_type=agent_decision)
4. RecordOutcome — PATCH decision with success/failure/quality
5. UpdatePromptStats — if LLM was used, update prompt usage stats
6. UpdateSkillStats — if skill was invoked, update success rate

Activities

  1. QueryPastDecisionsActivity — call memory service, filter by tool+entity_type
  2. RecordDecisionActivity — ingest agent_decision entity with reasoning
  3. RecordOutcomeActivity — update decision with outcome
  4. UpdatePromptStatsActivity — increment prompt usage_count + avg_quality
  5. UpdateSkillStatsActivity — increment skill invocation_count + success_rate

Acceptance Test

# Start local Temporal + memory service
TEMPORAL_HOSTPORT=localhost:7233 \
MEMORY_SERVICE_URL=http://localhost:8080 \
  go run cmd/worker/main.go &

# Trigger learning workflow
go run cmd/starter/main.go --workflow AgentLearningWorkflow \
  --input {"tool":"kubectl","task":"debug-pod","context":"CrashLoopBackOff"}

# Verify in memory service:
curl http://localhost:8080/memory/query -d {"query":"agent_decision kubectl","project":"poimen"}
# Should return the recorded decision
// workflow/agent_learning_test.go
func TestAgentLearningWorkflow_RecordsDecision(t *testing.T) {
    // Mock QueryPastDecisions returns empty (first time)
    // Mock task execution succeeds
    // Assert RecordDecision called with tool=kubectl
    // Assert RecordOutcome called with success=true
}

func TestAgentLearningWorkflow_UsesContext(t *testing.T) {
    // Mock QueryPastDecisions returns 2 past decisions
    // Assert past decisions passed to task execution
}

Effort

~300 LOC, 3 days

## Goal After each task execution, agent records its decision, reasoning, and outcome to memory service. Before each task, agent queries past decisions for context. ## Depends On - Memory service: agent entity endpoints (poimen-memory Phase 3.2-3.4) - This repo: synthesis activities registered (#14) ## Workflow: AgentLearningWorkflow ``` Input: { tool, task, context } 1. QueryPastDecisions — GET /memory/query?entity_type=agent_decision&tool=X 2. ExecuteTask — run actual task workflow (orchestrator/routing) 3. RecordDecision — POST /memory/ingest (entity_type=agent_decision) 4. RecordOutcome — PATCH decision with success/failure/quality 5. UpdatePromptStats — if LLM was used, update prompt usage stats 6. UpdateSkillStats — if skill was invoked, update success rate ``` ## Activities 1. `QueryPastDecisionsActivity` — call memory service, filter by tool+entity_type 2. `RecordDecisionActivity` — ingest agent_decision entity with reasoning 3. `RecordOutcomeActivity` — update decision with outcome 4. `UpdatePromptStatsActivity` — increment prompt usage_count + avg_quality 5. `UpdateSkillStatsActivity` — increment skill invocation_count + success_rate ## Acceptance Test ```bash # Start local Temporal + memory service TEMPORAL_HOSTPORT=localhost:7233 \ MEMORY_SERVICE_URL=http://localhost:8080 \ go run cmd/worker/main.go & # Trigger learning workflow go run cmd/starter/main.go --workflow AgentLearningWorkflow \ --input {"tool":"kubectl","task":"debug-pod","context":"CrashLoopBackOff"} # Verify in memory service: curl http://localhost:8080/memory/query -d {"query":"agent_decision kubectl","project":"poimen"} # Should return the recorded decision ``` ```go // workflow/agent_learning_test.go func TestAgentLearningWorkflow_RecordsDecision(t *testing.T) { // Mock QueryPastDecisions returns empty (first time) // Mock task execution succeeds // Assert RecordDecision called with tool=kubectl // Assert RecordOutcome called with success=true } func TestAgentLearningWorkflow_UsesContext(t *testing.T) { // Mock QueryPastDecisions returns 2 past decisions // Assert past decisions passed to task execution } ``` ## Effort ~300 LOC, 3 days
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: riotpiao-poimen/poimen-workflows#18