A Delta Engine agent with persistent Python REPL session using v1.5 simplified sessions.
This agent demonstrates Delta Engine's v1.5 session management for maintaining a persistent Python interactive session (REPL). Variables, imports, and function definitions persist across commands, using the simplified command-based execution model.
- ✅ Persistent Python REPL session (v1.5 simplified)
- ✅ Immediate output - No timing guesses, results returned instantly
- ✅ State preservation - Variables and imports persist across executions
- ✅ Error handling - Exit codes and stderr for debugging
- ✅ Simple API - Only 3 tools (start, exec, end)
delta run --agent examples/2-core-features/python-repl -m "Calculate the sum of numbers from 1 to 100"Simple Calculations:
delta run --agent examples/2-core-features/python-repl -m "Calculate 2^10 and show the result"Function Definitions:
delta run --agent examples/2-core-features/python-repl -m "Define a function to check if a number is prime, then test it with 17"Data Analysis:
delta run --agent examples/2-core-features/python-repl -m "Create a list of numbers 1-10, calculate their squares, and show the average"String Processing:
delta run --agent examples/2-core-features/python-repl -m "Reverse the string 'Hello World' and count vowels"- Start REPL:
python_start()→ creates Python session, returns session_id - Execute Code:
python_exec(session_id, code)→ runs code, returns output immediately - State Persists: Variables remain in memory between executions
- Cleanup:
python_end(session_id)→ terminates session
User Task: "Calculate factorial of 5"
Agent Workflow:
1. python_start()
→ Result: {"session_id": "sess_abc123", "status": "active"}
2. python_exec(sess_abc123, """
import math
print(math.factorial(5))
""")
→ Result: {"stdout": "120\n", "stderr": "", "exit_code": 0}
3. python_end(sess_abc123)
→ Result: {"status": "terminated"}
Response: "The factorial of 5 is 120."
Key v1.5 Advantages:
- ✅ Single
python_exec()call returns complete output - ✅ No separate read/wait steps needed
- ✅ JSON output format (stdout, stderr, exit_code)
- ✅ No timing complexity
See agent.yaml for tool definitions:
python_start- Start Python REPL sessionpython_exec- Execute code and get immediate outputpython_end- Terminate session
v1.5 Simplification: Only 3 tools needed (vs 5 in v1.4 PTY model)
delta run --agent examples/2-core-features/python-repl -m "Define a fibonacci function and calculate the 10th fibonacci number"The agent will:
- Start Python REPL
- Define multi-line function with proper indentation
- Call the function
- Return the result
delta run --agent examples/2-core-features/python-repl -m "Use numpy to create an array of 10 random numbers and calculate the mean"delta run --agent examples/2-core-features/python-repl -m "Try to divide by zero, handle the error, and show the error message"The agent can see Python errors and recover gracefully.
✅ Good: "Calculate the sum of squares of numbers 1-10"
❌ Vague: "Do some math"
If you need specific libraries:
delta run --agent examples/2-core-features/python-repl -m "Use pandas to create a DataFrame with columns 'name' and 'age', then show it"The agent can implement algorithms:
delta run --agent examples/2-core-features/python-repl -m "Implement bubble sort to sort the list [5, 2, 8, 1, 9]"# List all active Python sessions
delta-sessions list
# View session metadata
cat .sessions/sess_abc123/metadata.json
# View execution history
cat .sessions/sess_abc123/history.logIssue: "Session not found"
- Cause: Session ID incorrect or already terminated
- Solution: Check
delta-sessions listfor active sessions
Issue: exit_code is non-zero
- Cause: Python error occurred
- Solution: Check
stderrfield for error message
Issue: ImportError for library
- Cause: Library not installed on system
- Solution: Install with
pip install <library>before running agent
- Session Management Guide - Complete guide
- delta-sessions API Reference - CLI documentation
- v1.5 Architecture Design - Design rationale
- Interactive Shell Example - Bash session equivalent
MIT