> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# State Management

> Persist and share data across agent runs, team coordination, and workflow execution

**State** is data that persists across multiple runs within a session, enabling agents, teams, and workflows to maintain context and remember information.

Common use cases include managing user-specific data like shopping lists, todo lists, preferences, or any information that needs to persist across interactions. State is managed through `session_state`, which can be accessed and updated in tools, then automatically persisted to your database.

## How State Works

State in Agno follows this pattern:

1. **Initialize** - Set default `session_state` when creating agents, teams, or workflows
2. **Access** - Tools access state via `run_context.session_state`
3. **Update** - Modifications are automatically persisted to the database
4. **Load** - Subsequent runs in the same session retrieve the stored state

### Basic Example

Here's a simple agent that maintains a shopping list:

```python theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.run import RunContext

def add_item(run_context: RunContext, item: str) -> str:
    """Add an item to the shopping list."""
    run_context.session_state["shopping_list"].append(item)
    return f"Added {item}"

agent = Agent(
    db=SqliteDb(db_file="tmp/state.db"),
    session_state={"shopping_list": []},  # Default state
    tools=[add_item],
    instructions="Shopping list: {shopping_list}",  # State in instructions
)

agent.print_response("Add milk and eggs")
print(agent.get_session_state())  # {'shopping_list': ['milk', 'eggs']}
```

## Learn more

<CardGroup cols={3}>
  <Card title="Agent State" icon="robot" iconType="duotone" href="/state/agent/overview">
    Learn about state in agents.
  </Card>

  <Card title="Team State" icon="users" iconType="duotone" href="/state/team/overview">
    Learn about state in teams.
  </Card>

  <Card title="Workflow State" icon="diagram-project" iconType="duotone" href="/state/workflows/overview">
    Learn about state in workflows.
  </Card>
</CardGroup>

## Developer Resources

* View the [Agent schema](/reference/agents/agent)
* View the [Team schema](/reference/teams/team)
* View the [Workflow schema](/reference/workflows/workflow)
* View the [RunContext schema](/reference/run/run-context)
