State Management
State in LeafMesh is automatic and stored in Redis. This page covers patterns for working with state within agent executions.
Automatic State
LeafMesh auto-stores these without explicit calls:
- Session metadata and conversation history
- Agent yields after each execution
- Mesh communications between agents
- Coordination decisions and observations
The store behind all of this is configured in .env:
# .env
LEAFMESH_AGENCY_NAME=my-agency
LEAFMESH_STORE=redis
REDIS_HOST=localhost
REDIS_PORT=6379
# 1 hour for general data
REDIS_DEFAULT_TTL=3600
# 7 days for sessions (the default)
REDIS_SESSION_TTL=604800From 2.4.482 the store is set only in .env, never in the YAML.
Working with State in Intelligence Functions
Use the context and input_data parameters to access state:
async def counter_agent(llm_response, input_data, context):
session_id = context.get("session_id", "default")
yields = context.get("yields", {})
return {**llm_response, "session": session_id}Accessing Upstream Yields
When agent B is called by agent A via can_call, agent A's yields are passed as input_data:
async def checker(llm_response, input_data, context):
# input_data contains the upstream agent's yields
claimed_answer = input_data.get("answer")
return {"is_correct": claimed_answer == 42}Session-Scoped Storage
All state in LeafMesh is automatically scoped per session — session metadata, conversation history, agent yields, and mesh communications are kept isolated so different sessions never collide.
These records are managed automatically. Browse them in Studio's Sessions tab, or query them via the platform's REST API.
Next Steps
- Short-Term Memory — Full session management
- Redis Integration — Redis configuration
- Context Threading — Parallel session threads
LeafMesh — Explicit, inspectable state