Skip to content

Agent Smolagents

Agent Smolagents — mvp.agent_smolagents

Cluster: Agents & LLM | Type: component | MCP Tools: 26

Overview

Production-hardened HuggingFace smolagents tool-use agent wrapper supporting both CodeAgent and ToolCallingAgent variants. Generic runs default to safer ToolCallingAgent; CodeAgent is explicit and exposes bounded executor settings. Registered tools are opt-in by registry name during execution. Uses a LiteLLM-backed model so any OpenAI-compatible endpoint can serve as the reasoning engine; includes circuit breaker, retry, structured logging, metrics, failed-run persistence, read-only source-health/capability reporting, and top-level completion_state / admission_verdict envelope fields.

When to use:

  • Running tool-augmented reasoning loops where the agent writes and executes Python code to solve tasks
  • Integrating HuggingFace smolagents into the G6 pipeline with production-grade resilience
  • Benchmarking code vs toolcalling agent strategies on the same task with step-level trace capture

Example:

from mvp.agent_smolagents import AgentSmolagentsBlock, SmolagentsInput

block = AgentSmolagentsBlock(name="smolagents")
result = block.infer(SmolagentsInput(
    task="Calculate the 10th Fibonacci number using code.",
    agent_type="code",
    max_steps=5,
    model="gpt-4o-mini",
))
# result.ok → True; result.value → SmolagentsOutput with final_answer, tool_calls

Works well with: agent_openai, cegis, solver

Public API

AdmissionDecision

Decision on whether a smolagents code-execution run may be admitted.

Field Type Default
allowed bool required
verdict str 'deny'
authorized_imports tuple[str, ...] ()
executor_type str 'local'
rationale str ''
confidence float 0.0
completion_state str 'qualified-draft'
degraded bool False
raw_response str ''

AgentSmolagentsPlanner

Runtime-first facade that falls back to real deterministic floor logic.

Field Type Default
runtime AgentSmolagentsRuntime \| None None
last_llm_attempted bool field(default=False, init=False)

Methods:

decide(goal: str, context: str = '') -> AgentSmolagentsDecision

decide_admission(task_preview: str, agent_type: str, requested_imports: tuple[str, ...] | list[str], requested_executor: str, deterministic_allowed: bool) -> AdmissionDecision

ToolCall(BaseModel)

A single tool invocation recorded during agent execution.

Field Type Default
tool_name str required
arguments dict[str, object] Field(default_factory=dict)
result str ''

SmolagentsInput(BaseModel)

Input to AgentSmolagentsBlock.

Field Type Default
task str required
model str 'gpt-4o-mini'
api_key str ''
agent_type Literal['code', 'toolcalling'] 'toolcalling'
executor_type Literal['local', 'e2b', 'modal', 'docker', 'wasm'] 'local'
additional_authorized_imports list[str] Field(default_factory=list)
max_steps int 10
additional_context str ''
run_mode Literal['beta', 'production'] 'beta'
reviewer_signature str ''

SmolagentsOutput(BaseModel)

Output from AgentSmolagentsBlock.

Field Type Default
final_answer str required
steps_taken int required
tool_calls list[ToolCall] Field(default_factory=list)
model str ''
agent_type str ''
completion_state str 'qualified-draft'
admission_verdict str ''
degraded bool False
degradation_reason str ''
agentic_evidence dict[str, object] Field(default_factory=dict)

AgentSmolagentsBlock(LifecycleMixin, AIBlock[SmolagentsInput, SmolagentsOutput, None])

Production-hardened HuggingFace smolagents tool-use agent block.

Field Type Default
name str 'agent_smolagents'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)
tools list[object] field(default_factory=list)
api_key str ''
timeout float 30.0
retry_policy RetryPolicy field(default_factory=lambda: RetryPolicy(max_attempts=3, initial_delay=1.0, jitter=True, retryable_exceptions=(ConnectionError, TimeoutError, OSError)))
agentic_planner 'AgentSmolagentsPlanner \| None' None

Methods:

infer(data: SmolagentsInput) -> Result[SmolagentsOutput]

describe() -> dict[str, Any]

Return read-only source health and capabilities without executing an agent.

MCPSmolagentsInput(BaseModel)

Field Type Default
op SmolagentsOp required
task str ''
model str 'gpt-4o-mini'
api_key str ''
agent_type str 'toolcalling'
executor_type str 'local'
additional_authorized_imports_csv str ''
max_steps int 10
additional_context str ''
provider str ''
temperature float 0.0
name str ''
notes str ''
tags list[str] Field(default_factory=list)
query str ''
limit int 50
top_k int 5
tool_name str ''
tool_code str ''
inputs_json str ''
output_type str 'string'
run_id str ''
final_answer str ''
steps_taken int 0
duration_ms int 0
success bool True
tool_calls_json str ''
goal str ''
agent_type_scaffold str 'code'
tool_names_csv str ''
use_resource_bounds bool True
use_csf_guard bool False
use_subclass bool False
wraps_g6_component str ''
manager_model str 'gpt-4o-mini'
sub_agents_json str ''
log_run_id str ''
step_num int 0
step_type str ''
content str ''
run_mode str 'beta'
reviewer_signature str ''

MCPSmolagentsOutput(BaseModel)

Field Type Default
op str ''
ok bool True
error str ''
final_answer str ''
steps_taken int 0
duration_ms int 0
tool_calls list[dict] Field(default_factory=list)
session_id str ''
run_id str ''
log_id str ''
tool_id str ''
records list[dict] Field(default_factory=list)
count int 0
code str ''
summary dict Field(default_factory=dict)
info dict Field(default_factory=dict)
completion_state str 'qualified-draft'
admission_verdict str ''
degraded bool False
degradation_reason str ''
agentic_evidence dict Field(default_factory=dict)

MCPSmolagentsRecord(BaseModel)

Field Type Default
id int 0
name str ''
data dict Field(default_factory=dict)
timestamp str ''

AdaptSmolagentsMCPBlock(AIBlock[MCPSmolagentsInput, MCPSmolagentsOutput, dict])

Full-featured smolagents block with SQLite persistence.

Field Type Default
name str 'adapt_smolagents_mcp'
db_path str ':memory:'
resource_bounds ResourceBounds \| None None
usage ResourceUsage field(default_factory=ResourceUsage)

Methods:

infer(data: MCPSmolagentsInput) -> Result[MCPSmolagentsOutput]

SmolagentsStore

Sync SQLite smolagents store with 5 tables.

Constructor:

Parameter Type Default
db_path str ':memory:'

Methods:

save_session(name: str, model: str, agent_type: str, max_steps: int, tools_json: str, provider: str, notes: str, config_json: str) -> str

load_session(name: str) -> dict[str, Any] | None

list_sessions(limit: int = 50) -> list[dict[str, Any]]

delete_session(name: str) -> bool

add_run(task: str, model: str, agent_type: str, provider: str, final_answer: str, steps_taken: int, duration_ms: int, tool_calls_json: str, success: bool, notes: str, tags: list[str]) -> str

get_run(run_id: str) -> dict[str, Any] | None

query_runs(query: str = '', limit: int = 50) -> list[dict[str, Any]]

summarize_runs() -> dict[str, Any]

register_tool(name: str, description: str, code: str, inputs_json: str, output_type: str, tags: list[str]) -> str

get_tool(name: str) -> dict[str, Any] | None

list_tools(limit: int = 50) -> list[dict[str, Any]]

delete_tool(name: str) -> bool

add_log(run_id: str, step_num: int, step_type: str, content: str, tool_name: str) -> str

query_logs(run_id: str = '', limit: int = 50) -> list[dict[str, Any]]

search_runs(query: str, top_k: int = 5) -> list[dict[str, Any]]

search_tools(query: str, top_k: int = 5) -> list[dict[str, Any]]

count_all() -> dict[str, int]

Functions

build_agent_smolagents_planner(default_enabled: bool = True, llm_backend: str | None = None) -> AgentSmolagentsPlanner | None

Single shared factory for the agentic admission planner (ON-BY-DEFAULT).

MCP Tools

Operation Source
run smolagents_mcp
run_code_agent smolagents_mcp
run_toolcalling_agent smolagents_mcp
save_session smolagents_mcp
load_session smolagents_mcp
list_sessions smolagents_mcp
delete_session smolagents_mcp
record_run smolagents_mcp
query_runs smolagents_mcp
get_run smolagents_mcp
summarize_runs smolagents_mcp
register_tool smolagents_mcp
get_tool smolagents_mcp
list_tools smolagents_mcp
delete_tool smolagents_mcp
scaffold_tool smolagents_mcp
scaffold_agent smolagents_mcp
scaffold_multi_agent smolagents_mcp
list_model_backends smolagents_mcp
list_builtin_tools smolagents_mcp
record_log smolagents_mcp
query_logs smolagents_mcp
search_runs smolagents_mcp
search_tools smolagents_mcp
smolagents_info smolagents_mcp
list_patterns smolagents_mcp