dspy-codeact
Installation
SKILL.md
Build Agents That Write and Execute Code with dspy.CodeAct
Guide the user through building DSPy agents that solve problems by generating and running Python code, rather than calling tools through a fixed interface.
Step 1 — Gather context
Ask the user before writing code:
- What task should the agent perform? (e.g., data analysis, math computation, file processing, custom calculation) — this guides tool design and
max_iterschoice. - Do you have existing Python functions to expose as tools, or do they need to be defined? CodeAct requires plain functions with type hints and docstrings — not classes or lambdas.
- What LM provider are you using? Any DSPy-supported provider works — OpenAI, Anthropic, local models, etc.
- Will you optimize the agent on training examples, or use it for one-off tasks? Optimization with BootstrapFewShot significantly improves performance on repeated tasks.
What is CodeAct
dspy.CodeAct is a DSPy module that creates agents which write Python code to accomplish tasks. Instead of selecting from a predefined set of tool calls (like ReAct), CodeAct generates executable code snippets that use provided tools as Python functions.
The agent works in a loop: