Skip to content

Anvil Class

The Anvil class is the main entry point for the SDK.

from anvil import Anvil
anvil = Anvil(
api_key: str | None = None,
firecrawl_key: str | None = None,
tools_dir: str | Path = "./anvil_tools",
self_healing: bool = True,
max_heal_attempts: int = 2,
use_stub: bool = False,
model: str | None = None,
provider: str = "anthropic",
log_file: str | Path | None = None,
interactive_credentials: bool = True,
env_file: str | Path | None = None,
verified_mode: bool = False,
security_policy: SecurityPolicy | None = None,
mode: str = "local",
)
ParameterTypeDefaultDescription
api_keystr | NoneNoneLLM provider API key. Falls back to environment variable.
firecrawl_keystr | NoneNoneFireCrawl API key for documentation fetching.
tools_dirstr | Path"./anvil_tools"Directory to store generated tools.
self_healingboolTrueEnable automatic tool regeneration on failure.
max_heal_attemptsint2Maximum self-healing attempts per tool.
use_stubboolFalseUse stub generator (no LLM calls).
modelstr | NoneNoneLLM model to use. Provider-specific default if None.
providerstr"anthropic"LLM provider: “anthropic”, “openai”, or “grok”.
log_filestr | Path | NoneNonePath to log file for event logging.
interactive_credentialsboolTrueEnable interactive credential prompts.
env_filestr | Path | NoneNonePath to .env file for credentials.
verified_modeboolFalseVerify generated code in sandbox.
security_policySecurityPolicy | NoneNoneCustom security policy for sandbox.
modestr"local"Generator mode: “local”, “stub”, or “cloud”.

Create or load a tool.

tool = anvil.use_tool(
name: str,
intent: str,
docs_url: str | None = None,
inputs: list[InputParam] | None = None,
) -> Tool
ParameterTypeDescription
namestrUnique identifier for the tool.
intentstrNatural language description of what the tool does.
docs_urlstr | NoneURL to API documentation.
inputslist[InputParam] | NoneExplicit input parameter definitions.

Tool - A tool object ready for execution.

tool = anvil.use_tool(
name="search_github",
intent="Search GitHub repositories by query",
docs_url="https://docs.github.com/en/rest/search",
inputs=[
InputParam(name="query", param_type="str", required=True),
InputParam(name="sort", param_type="str", default="stars"),
]
)

List all available tools in the tools directory.

tools = anvil.list_tools() -> list[str]

list[str] - List of tool names.

tools = anvil.list_tools()
print(tools) # ["search_github", "get_weather", "send_email"]

Get metadata about a specific tool.

info = anvil.get_tool_info(name: str) -> dict | None
ParameterTypeDescription
namestrTool name.

dict | None - Tool metadata or None if not found.

info = anvil.get_tool_info("search_github")
print(info)
# {
# "name": "search_github",
# "intent": "Search GitHub repositories",
# "version": "1.0",
# "status": "active",
# "created_at": "2025-01-18T10:00:00Z",
# ...
# }

Get the source code of a generated tool.

code = anvil.get_tool_code(name: str) -> str | None
ParameterTypeDescription
namestrTool name.

str | None - Tool source code or None if not found.

code = anvil.get_tool_code("search_github")
print(code)

Reset the self-healing attempt counter.

anvil.reset_heal_attempts(name: str | None = None) -> None
ParameterTypeDescription
namestr | NoneTool name, or None to reset all.
# Reset specific tool
anvil.reset_heal_attempts("search_github")
# Reset all tools
anvil.reset_heal_attempts()

Get the status of the sandbox system.

status = anvil.get_sandbox_status() -> dict

dict - Sandbox status information.

status = anvil.get_sandbox_status()
print(status)
# {
# "enabled": True,
# "active_driver": "docker",
# "docker_available": True,
# "policy": {...}
# }

Access the event logger.

logger = anvil.logger # AnvilLogger

Access the sandbox manager.

sandbox = anvil.sandbox # SandboxManager

Get the current generator mode.

mode = anvil.mode # "local", "stub", or "cloud"

Define input parameters for tools.

from anvil import InputParam
param = InputParam(
name: str,
param_type: str = "str",
required: bool = True,
description: str = "",
default: Any = None,
)
FieldTypeDefaultDescription
namestrrequiredParameter name.
param_typestr"str"Type: “str”, “int”, “float”, “bool”, “list”.
requiredboolTrueWhether the parameter is required.
descriptionstr""Help text for the parameter.
defaultAnyNoneDefault value if not provided.

Raised when tool execution fails (if self-healing is disabled or exhausted).

Raised when a required dependency is missing.