Goal Tracking
Category: Agent Behavior
Problem
Long-running agents lose track of user goals across conversations. A user might say "I want to launch my app by Friday" in one session, but three sessions later the agent has no memory of this objective. Without explicit goal persistence, agents become reactive instead of proactive, unable to remind users of deadlines or track progress toward stated objectives.
Architecture
This pattern stores explicit user goals with status metadata (active, completed, abandoned) and high importance scores. At the start of each session, the agent recalls all active goals to maintain continuity. Goals are updated rather than duplicated when their status changes.
Flow
- Detect goal statements in user messages (explicit intentions or deadlines)
- Store goals with status, priority, and optional deadline metadata
- Recall active goals at session start to provide proactive context
- Update goal status when user reports completion or changes plans
Implementation
from dakera import Dakera
import time
client = Dakera(base_url="http://localhost:3300", api_key="dk-...")
# Store a new user goal
def create_goal(user_id: str, goal: str, deadline: str = None, priority: str = "medium"):
"""Persist a user goal with tracking metadata."""
client.memory.store(
content=goal,
namespace=f"user-{user_id}-goals",
metadata={
"type": "goal",
"status": "active",
"priority": priority,
"deadline": deadline,
"created_at": time.time(),
"importance": 0.95
}
)
# Create goals from user statements
create_goal("alice", "Launch the MVP by end of June", deadline="2024-06-30", priority="high")
create_goal("alice", "Migrate database from MySQL to PostgreSQL", priority="medium")
create_goal("alice", "Write API documentation for v2 endpoints", priority="low")
# Recall all active goals at session start
def get_active_goals(user_id: str) -> list:
"""Retrieve all active goals for session context injection."""
results = client.memory.recall(
query="active goals and objectives",
namespace=f"user-{user_id}-goals",
top_k=20,
metadata_filter={"status": "active"}
)
goals = results["results"]
goals.sort(key=lambda x: {"high": 0, "medium": 1, "low": 2}[x["metadata"]["priority"]])
return goals
# Mark a goal as completed
def complete_goal(user_id: str, goal_query: str):
"""Find and mark a goal as completed."""
results = client.memory.recall(
query=goal_query,
namespace=f"user-{user_id}-goals",
top_k=1,
metadata_filter={"status": "active"}
)
if results["results"]:
memory_id = results["results"][0]["id"]
client.memory.store(
content=results["results"][0]["content"],
namespace=f"user-{user_id}-goals",
metadata={"type": "goal", "status": "completed", "completed_at": time.time()}
)
# Session start: inject active goals
active = get_active_goals("alice")
for g in active:
print(f"[{g['metadata']['priority']}] {g['content']}")
When to Use This Pattern
- Project management assistants tracking deliverables
- Personal productivity agents with recurring check-ins
- Customer success bots monitoring onboarding milestones
- Any agent that should proactively reference user intentions
Key Considerations
- Use high importance (0.9+) for goals so they surface reliably during recall
- Include deadline metadata to enable time-aware prompting
- Handle goal conflicts when users state contradictory objectives
- Consider a separate "abandoned" status for goals the user explicitly drops