CaveAgent enables stateful runtime management for LLM agents, allowing injection, manipulation, and retrieval of Python objects across turns. Operations teams can use it to build persistent, stateful workflows with Claude agents, integrating with Python-based tools and workflows.
git clone https://github.com/acodercat/cave-agent.gitCaveAgent transforms LLM agents from text-in-text-out systems into stateful runtime operators that work with native Python objects. It provides two runtime backends—IPythonRuntime for same-process execution with zero-copy object access, and IPyKernelRuntime for process-isolated execution with crash resilience. You can inject DataFrames, database connections, models, and custom class instances as first-class variables that persist across turns without serialization. The runtime executes Python code directly, retrieves manipulated objects as native types, and supports both function calling and agent skills. This approach eliminates context window bloat from large state objects and enables complex workflows like data visualization, multi-agent coordination, and real-time streaming.
[{"step":"Initialize CaveAgent in your Python environment. Ensure you have the required dependencies installed (e.g., `pip install cave-agent`).","tip":"Run `import cave_agent; agent = cave_agent.CaveAgent()` to start a new agent session with stateful capabilities."},{"step":"Inject a Python object into the agent's state using `agent.inject_object(OBJECT_NAME, OBJECT_STATE)`. Choose a descriptive name for the object (e.g., `user_session`, `config_manager`).","tip":"Use dictionaries or custom classes for complex state management. Avoid injecting large objects (>10MB) to prevent performance issues."},{"step":"Retrieve the object in subsequent turns with `agent.get_object(OBJECT_NAME)` to inspect or modify its state.","tip":"Always retrieve the object before modifying it to ensure you're working with the latest state. Use deep copies if you need to manipulate the state without affecting the original."},{"step":"Update the object's state using `agent.update_object(OBJECT_NAME, UPDATED_STATE)` after making changes.","tip":"Validate the updated state before calling `update_object` to avoid corrupting the persistent state. Log changes for auditing purposes."},{"step":"Chain operations across multiple agent turns by referencing the same object name. The state will persist until the agent session ends or the object is explicitly removed.","tip":"Use `agent.remove_object(OBJECT_NAME)` to clean up objects when they're no longer needed, especially in long-running workflows."}]
Data analysis and visualization workflows with persistent DataFrames and chart configurations
Database operations where agents execute SQL queries against live connections
Multi-turn stateful workflows requiring object manipulation across agent turns
Sandboxed code execution in multi-tenant environments using process isolation
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/acodercat/cave-agentCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Use CaveAgent to inject the Python object [OBJECT_NAME] with the following state: [OBJECT_STATE]. Then, retrieve and modify the object to [MODIFICATION_GOAL] in the next turn. Ensure the object persists across agent interactions and tool calls. Provide the updated state of the object after the modification.
```python
# Initial state injection
from cave_agent import CaveAgent
agent = CaveAgent()
# Injecting a persistent object (e.g., a configuration manager)
config_manager = {
"api_keys": {
"weather_service": "abc123-xyz456",
"payment_gateway": "secure_key_789"
},
"retry_policy": {
"max_attempts": 3,
"backoff_seconds": [1, 5, 10]
},
"last_updated": "2024-05-20T14:30:00Z"
}
agent.inject_object("config_manager", config_manager)
# First interaction: Retrieve and update the object
retrieved_config = agent.get_object("config_manager")
retrieved_config["api_keys"]["weather_service"] = "new_key_999"
retrieved_config["last_updated"] = "2024-05-20T15:15:00Z"
agent.update_object("config_manager", retrieved_config)
# Second interaction: Verify persistence and state
final_config = agent.get_object("config_manager")
print(final_config)
```
**Output:**
```
{
"api_keys": {
"weather_service": "new_key_999",
"payment_gateway": "secure_key_789"
},
"retry_policy": {
"max_attempts": 3,
"backoff_seconds": [1, 5, 10]
},
"last_updated": "2024-05-20T15:15:00Z"
}
```
The `config_manager` object was successfully injected, retrieved, modified, and persisted across two agent interactions. The `weather_service` API key was updated, and the `last_updated` timestamp reflects the most recent change. Operations teams can use this pattern to maintain stateful configurations, session data, or workflow variables without losing context between agent turns.Cloud ETL platform for non-technical data integration
IronCalc is a spreadsheet engine and ecosystem
Get more done every day with Microsoft Teams – powered by AI
Customer feedback management made simple
Enterprise workflow automation and service management platform
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan