Why
Enable multi-iteration agent workflows (like ActionFinder) where agents can maintain context across separate executions.
Current limitation: Agents have no memory between iterations. Each run starts fresh, requiring all context to re-passed via prompts.
This PR enables: Simple session resumption - just call agent.resume(new_prompt) to continue with full context preservation.
What
Simplified Session Resumption API
Before (verbose):
# Session 1
agent1 = GenericAgent(AgentConfig(...))
response1 = agent1.run()
# Manual session ID capture
session_id = get_claude_session_id(start_time, cwd)
# Session 2 - recreate entire agent with resume_from
agent2 = GenericAgent(AgentConfig(..., resume_from=session_id))
response2 = agent2.run()
After (simple):
# Session 1
agent = GenericAgent(AgentConfig(...))
response1 = agent.run()
# Session 2 - just call resume()!
response2 = agent.resume("What did I ask before?")
Implementation Details
1. AgentResponse.session_id: Track Claude session IDs automatically
class AgentResponse:
def __init__(self, ..., session_id: Optional[str] = None):
self.session_id = session_id # Captured from .jsonl files
2. GenericAgent._last_session_id: Agent tracks its session internally
def __init__(self, config: AgentConfig):
# ...
self._last_session_id: Optional[str] = None
3. agent.resume(user_prompt): New method for easy resumption
def resume(self, user_prompt: str, max_turns=None, timeout=None):
"""Resume with new prompt, continuing previous session."""
# Creates resumed agent automatically
# Inherits all config/tools from original session
# Returns AgentResponse with result
4. Claude Provider: Auto-captures session_id from .claude/projects/ directory
session_id = _get_claude_session_id(start_time, cwd)
return AgentResponse(..., session_id=session_id)
5. OpenAI Provider: Raises NotImplementedError if resume requested
6. Simple Tracing Test: Optional session resumption test (config flag: test_session_resumption)
Files Changed
cortex/generic/agent.py: Added resume() method and session tracking
cortex/generic/agent_provider/claude.py: Auto-capture session_id
cortex/generic/agent_provider/openai.py: Graceful rejection
cortex/workflows/simple_tracing.py: Integration test with new API
common/configs.py: Added test_session_resumption config field
test_working_resume.py: Updated to demonstrate simplified API
SESSION_RESUMPTION.md: Documentation
How to test
Local test (already passed):
uv run python test_working_resume.py
Expected output:
✅ Session established: 88a53f47-c6e6-45e5-9132-1cc2d1f7ffdc
✅ SUCCESS: Session resumption works! Context was preserved.
- Agent remembered the name: Alice
- Agent remembered the number: 777
Staging test (after merge):
curl -X POST 'https://staging-integrations-api.composio.io/workflows/simple-tracing/run' \
-H 'Content-Type: application/json' \
-d '{"app_name": "test", "model_provider": "claude", "test_session_resumption": true}'
Then check logs for:
session_resumption_tested: true
session_resumption_working: true
Notes
- Session resumption only works for Claude provider (Claude CLI stores sessions in
~/.claude/projects/)
- OpenAI provider raises
NotImplementedError if resumption requested
- Agent automatically tracks session_id internally - no manual capture needed
- Config flag
test_session_resumption defaults to False (opt-in for testing)
- Full context preservation verified in local tests