Skip to content

API Reference — Python

Package toolnexus (PyPI, Python ≥ 3.11). See the combined API Reference for every symbol shown in eight-language synced tabs.

  • create_toolkit(...) -> Toolkit (async)
  • Keyword args: mcp_config, skills_dir, skills, skill_provider, skills_filter, skill_sample_limit, builtins, agents, extra_tools, wait_for.
  • Equivalents: createToolkit (js) · CreateToolkit (go) · Toolkit.create (java) · Toolkit.CreateAsync (c#) · Toolnexus.create_toolkit (elixir).
  • load_skills(dirs=None, *, skills=None, filter=None, sample_limit=0) -> SkillSource
  • list_skills(dirs=None, *, skills=None) -> SkillInventory — .skills, .skipped (SkillSkip.reason: missing-name · malformed-frontmatter · duplicate-name · unreadable).
  • SkillDef(name, content, description=None, resources=None, base=None)
  • skill_provider may be sync or async.
  • Equivalents: loadSkills / listSkills (js) · LoadSkillsWith / ListSkills (go) · SkillSource.loadWith / listSkills (java) · SkillSource.LoadWith / ListSkills (c#) · Toolnexus.Skill.load / Toolnexus.Skill.list (elixir).
  • load_mcp(config) -> McpSource (async)
  • to_openai(tk) · to_anthropic(tk) · to_gemini(tk)
  • create_client(...) -> Client → await client.ask(prompt, tk).

Tools you build — native, HTTP, built-ins

Section titled “Tools you build — native, HTTP, built-ins”
  • @tool / define_tool(fn, *, name?, description?, input_schema?) — schema inferred from type hints + docstring.
  • http_tool(*, name, description, method, url, headers?, query?, body?, result_mode?, timeout?) — timeout in seconds.
  • builtins toggle → ten built-ins: bash · read · write · edit · grep · glob · webfetch · question · apply_patch · todowrite.
  • Equivalents: defineTool / httpTool (js) · NativeTool / HTTPTool (go) · NativeTool.of / HttpTool.of (java) · NativeTool.Of / HttpTool.Of (c#) · Toolnexus.Native.define_tool / Toolnexus.Http.tool (elixir).
  • agent(name, *, does, uses?, soul?, soul_file?, team?, budget?, model?, wait_for?) -> Agent.
  • await agent.run(prompt, *, llm={...}, ...) -> TaskResult — .status, .text, .total_tokens, .runtime.
  • agent.as_tool(**rt_opts) -> Tool · compose_soul(dir) -> (soul, found) · Budget(...).
  • Equivalents: agents.agent / .run / .asTool / composeSoul (js) · agents.New (go) · Agents.agent (java/elixir) · new Agent (c#).
  • await tk.serve(addr, *, client, a2a: A2AConfig, on_task?, mcp?, on_call?) -> ServeHandle.
  • agent(card, *, headers?, timeout?, poll_every?) + create_toolkit(agents=[...]) / await tk.add_agent(card_url).
  • Equivalents: tk.serve / tk.addAgent (js) · Serve / AddAgent (go) · serve / addAgent (java) · ServeAsync / AddAgentAsync (c#) · Toolkit.serve / Toolkit.add_agent (elixir).
  • wait_for (toolkit option; callable (Request) -> Answer).
  • Request(id, kind, prompt, url?, data?, expiresAt?) · Answer(id, ok, data?, reason?).
  • pending(*, kind, prompt, url?, data?) · auth_required(url, prompt?) · pending_of(result).
  • Equivalents: waitFor / pending / authRequired / pendingOf (js) · WaitFor / Pending (go) · waitFor / ToolResult.pending (java) · WithWaitFor / ToolResult.Pending (c#) · wait_for / ToolResult.pending? (elixir).

Guide: Media generation · recipe: Generate images, video and speech · SPEC §7G.

  • create_media(clients: MediaClient | list[MediaClient]) -> Media — a verb goes to the first client whose supports(verb) is true; only MediaUnavailableError falls through to the next one.
  • Built-in clients, each X(config: MediaConfig | dict | None = None, **kw): A2EMediaClient (A2E_API_KEY) · ElevenLabsMediaClient (ELEVENLABS_API_KEY) · OpenAIMediaClient (OPENAI_API_KEY) · OpenRouterMediaClient (OPENROUTER_API_KEY) · FalMediaClient (FAL_API_KEY) — and the CLI clients GrokMediaClient (grok) · CodexMediaClient (codex).
  • MediaConfig(model, models: dict[str, str], key, url, command: str | list[str], loop: LoopConfig, gather: GatherConfig, http_client: MediaTransport) · LoopConfig(interval_ms, timeout_ms, on_progress) · GatherConfig(mode: "url" | "download" | "inline", dir, max_bytes, keep) — loop / gather also take dicts (snake_case or camelCase keys). key defaults to the env var read at call time; timeout_ms 600000; gather.mode default download (style clients url) into <tmp>/toolnexus-media, max_bytes 100 MiB. on_progress({"verb", "client", "jobId", "status", "elapsedMs"}) may be sync or async.
  • MediaTransport — blocking request(method, url, headers, body, timeout) -> (status, body[, headers]), run in a worker thread; it must not follow redirects (the client does, under §7G.8). Default UrllibMediaTransport.
  • Verbs (all async, return MediaResult; each also takes deadline=, progress=, provider_options=): image(prompt, *, width, height, aspect_ratio, seed) · video(prompt, *, image, seconds, aspect_ratio) · speech(text, *, voice) · music(prompt, *, seconds, instrumental, lyrics) · transcribe(audio, *, language) · clone_voice(name, samples) · talk(image, *, audio, text, voice). File inputs take a URL or a local path; None arguments are not sent.
  • await media.generate(verb, args=None, provider_options=None, *, deadline=None, progress=None, ctx=None) — the raw call; verb is the canonical name ("cloneVoice", not "clone_voice"). media.supports(verb) -> bool.
  • MediaResult(files: list[MediaFile], text, job_id, status) · MediaFile(type, mime_type, url, path, data); .to_dict() gives the canonical camelCase shape.
  • MediaClient (protocol): name, supports(verb), optional args(verb) -> [{"name", "required"}] and async image(args, ctx) … talk(args, ctx). BaseMediaClient routes all seven to one async generate(verb, args, ctx: MediaContext). MediaContext(deadline, progress, provider_options).
  • media.tools() -> list[Tool] — generate_image · generate_video · generate_speech · generate_music · transcribe_audio · clone_voice · talking_video (source "media"), one per verb any client supports; or create_toolkit(media=media). Only image parts are sent back to the model.
  • RunResult.files — list of dicts {type, mimeType, url?, data?, from, callId}, in call order; the same parts are on tool_calls[i]["parts"].
  • Errors: the function face raises MediaError (str(e) is the exact §7G message; .status, .job_id); MediaUnavailableError is its unavailable subclass. A media tool never raises (is_error=True). asyncio.CancelledError always propagates, from the function face and the tool face alike.
  • Advanced: style_media_client(style, config=None) / StyleMediaClient turn a JSON style into a client; load_media_style(path) -> dict reads one.
  • Equivalents: createMedia (js) · CreateMedia (go) · Media.create (java) · Media.Create (c#) · Toolnexus.Media.create (elixir) · toolnexus.media/create-media (clojure) · create_media (rust).