skills/ai-taking-actions/SKILL.md
Build AI that takes actions, calls APIs, and does things autonomously. Use when you need AI to call APIs, use tools, perform calculations, search the web and act on results, interact with databases, or do multi-step tasks. Also AI that does things not just talks, tool-using AI agent, AI calls external APIs, function calling with DSPy, build AI that books appointments, AI workflow automation, agent that searches and acts on results, AI that updates databases, autonomous AI agent, AI performs multi-step tasks, give LLM access to tools, agentic AI workflow, AI agent for DevOps, build AI assistant that takes actions, MCP tool integration with AI, AI that can browse and click, LLM with tool access.
npx skillsauth add lebsral/dspy-programming-not-prompting-lms-skills ai-taking-actionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide the user through building AI that reasons and takes actions — calling APIs, using tools, and completing multi-step tasks. Uses DSPy's ReAct and CodeAct agent modules.
Ask the user:
Tools are Python functions with type hints and docstrings. DSPy uses these to tell the AI what's available:
def search(query: str) -> str:
"""Search the web for information."""
# Your search implementation
return "search results..."
def calculate(expression: str) -> float:
"""Evaluate a mathematical expression."""
return dspy.PythonInterpreter({}).execute(expression)
def lookup_database(table: str, query: str) -> str:
"""Query the database for records matching the query."""
# Your database logic
return "query results..."
Tool requirements:
| | ReAct | CodeAct |
|---|---|---|
| Best for | General tool-calling (APIs, search, databases) | Tasks where writing code is more natural (math, data transforms) |
| How it works | Alternates thinking and tool calls | Writes and executes Python code with tool access |
| Tool types | Any callable, dspy.Tool, LangChain tools | Pure functions only (no callable objects or external deps) |
| Default max_iters | 20 | 5 |
| Start here? | Yes — most general-purpose | When the task is inherently code-centric |
The standard choice. Alternates between thinking and acting:
import dspy
lm = dspy.LM("openai/gpt-4o-mini") # or "anthropic/claude-sonnet-4-5-20250929", etc.
dspy.configure(lm=lm)
agent = dspy.ReAct(
"question -> answer",
tools=[search, calculate],
max_iters=8, # default is 20; lower for simple tasks to save cost
)
result = agent(question="What is the population of France divided by 3?")
print(result.answer)
Writes and executes Python code. Only accepts pure functions as tools — no callable objects or undeclared dependencies:
agent = dspy.CodeAct(
"question -> answer",
tools=[calculate], # pure functions only
max_iters=5, # default is 5
)
result = agent(question="Calculate the compound interest on $1000 at 5% for 10 years")
print(result.answer)
class ResearchBot(dspy.Module):
def __init__(self):
self.agent = dspy.ReAct(
"question, context -> answer",
tools=[search, lookup_database],
max_iters=8,
)
def forward(self, question):
# Add initial context or pre-processing
context = "Use search for general questions, database for specific records."
return self.agent(question=question, context=context)
def action_metric(example, prediction, trace=None):
# Check if the final answer is correct
return prediction.answer.strip().lower() == example.answer.strip().lower()
# For open-ended tasks, use an AI judge
class JudgeResult(dspy.Signature):
"""Judge if the AI's answer correctly addresses the question."""
question: str = dspy.InputField()
expected: str = dspy.InputField()
actual: str = dspy.InputField()
is_correct: bool = dspy.OutputField()
def judge_metric(example, prediction, trace=None):
judge = dspy.Predict(JudgeResult)
result = judge(
question=example.question,
expected=example.answer,
actual=prediction.answer,
)
return result.is_correct
# Optimize the AI's reasoning prompts
optimizer = dspy.BootstrapFewShot(metric=action_metric, max_bootstrapped_demos=4)
optimized = optimizer.compile(agent, trainset=trainset)
For action-taking AI, MIPROv2 often works better since it can optimize the reasoning instructions:
optimizer = dspy.MIPROv2(metric=action_metric, auto="medium")
optimized = optimizer.compile(agent, trainset=trainset)
LangChain has 100+ pre-built tools (search engines, Wikipedia, SQL databases, web scrapers, etc.). Convert any of them to DSPy tools with one line:
import dspy
from langchain_community.tools import DuckDuckGoSearchRun, WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
# Convert LangChain tools to DSPy tools
search = dspy.Tool.from_langchain(DuckDuckGoSearchRun())
wikipedia = dspy.Tool.from_langchain(WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper()))
# Use in any DSPy agent
agent = dspy.ReAct(
"question -> answer",
tools=[search, wikipedia],
max_iters=5,
)
When to use LangChain tools vs writing your own:
| Use LangChain tools when... | Write your own when... | |------------------------------|------------------------| | There's an existing tool for it (search, Wikipedia, SQL) | You need custom business logic | | You want quick prototyping | You need tight error handling | | The tool wraps a standard API | You're wrapping an internal API |
Install the tools you need:
pip install langchain-community # DuckDuckGo, Wikipedia, requests, etc.
For more LangChain tools, see the LangChain community tools docs.
dspy.Predict or dspy.ChainOfThought instead. Agents add overhead (multiple LM calls per request).max_iters=5 for ReAct but the default is 20. The API default of 20 is generous — for most tasks, 5-10 iterations suffice. Set it explicitly to control cost, but do not assume 5 is the framework default.dspy.configure(lm=lm) before creating agents. The agent will fail at runtime with confusing errors if no LM is configured. Always configure the LM before instantiating any module.Install any skill:
npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill <name>
/ai-coordinating-agents/ai-improving-accuracy/dspy-react or /dspy-code-act (if available)/dspy-signatures/ai-do if you do not have it — it routes any AI problem to the right skill and is the fastest way to work: npx skills add lebsral/DSPy-Programming-not-prompting-LMs-skills --skill ai-dotools
See what is happening during optimizer.compile() instead of waiting blind. Use when you want to watch optimization progress, see scores as they come in, know if your optimizer is working, check if optimization is stuck, understand why optimization is taking too long, get live progress during compile, monitor convergence, detect overfitting during optimization, interpret optimization results, or pick the right tool for watching optimization. Also used for optimizer progress bar, is my optimizer doing anything, optimization seems stuck, how long will optimization take, watch GEPA run, watch MIPROv2 run, live optimization dashboard, optimizer not improving, scores not going up, optimization taking forever, see what optimizer is doing, debug slow optimization, optimization visibility, optimizer metrics, track compile progress, optimization observability.
testing
Use when you want the highest-quality prompt optimization DSPy offers — jointly optimizes instructions and few-shot demos, with auto=light/medium/heavy presets. Common scenarios - you want the best possible accuracy from prompt optimization, jointly tuning instructions and few-shot demonstrations, using auto presets for different compute budgets, or when COPRO or BootstrapFewShot alone are not reaching your accuracy target. Related - ai-improving-accuracy, dspy-copro, dspy-bootstrap-few-shot. Also used for dspy.MIPROv2, best DSPy optimizer, highest quality optimization, auto=light medium heavy, joint instruction and demo optimization, most powerful prompt optimizer, MIPROv2 vs COPRO vs BootstrapFewShot, which optimizer should I use, state of the art prompt optimization, when to use MIPROv2, optimize both instructions and examples, heavy optimization for production, best optimizer for accuracy.
testing
Use LangWatch for DSPy auto-tracing and real-time optimizer progress. Use when you want to set up LangWatch, langwatch.dspy.init, auto-tracing DSPy, real-time optimization dashboard, optimizer progress tracking, app.langwatch.ai, or DSPy optimizer dashboard. Also used for langwatch setup, pip install langwatch, langwatch trace, optimizer progress, real-time optimization, watch optimizer run, LangWatch self-hosted, langwatch docker, langwatch vs langtrace, langwatch autotrack_dspy.
data-ai
Use when you want to optimize instructions without few-shot examples — a lightweight alternative to COPRO when you do not have or do not want to use demonstrations. Common scenarios - optimizing instructions when you do not have or do not want to use few-shot demonstrations, lightweight instruction search as a first step, tasks where examples in the prompt confuse the model, or when you want fast instruction optimization without the cost of COPRO. Related - ai-improving-accuracy, dspy-copro, dspy-miprov2. Also used for dspy.GEPA, instruction optimization without demos, lightweight prompt optimization, optimize instructions only, no few-shot examples needed, GEPA vs COPRO, quick instruction search, when demonstrations hurt performance, zero-shot optimization, instruction-only optimizer, simplest instruction tuner, fast prompt optimization, skip few-shot and just tune instructions, optimize Pydantic field descriptions, GEPA structured output, GEPA does not optimize field desc.