Skip to main content

Multi-turn tool-calling agent runtime for embedding the mycode agent loop.

Project description

mycode-sdk

Lightweight Python SDK for building agents.

Install

uv add mycode-sdk
# or
pip install mycode-sdk

Quick start

import asyncio

from mycode import Agent, bash_tool, read_tool


async def main() -> None:
    agent = Agent(
        model="claude-sonnet-4-6",
        api_key="YOUR_API_KEY",
        cwd=".",
        tools=[read_tool, bash_tool],
    )

    async for event in agent.achat("Read pyproject.toml and tell me the project name."):
        if event.type == "text":
            print(event.data["delta"], end="", flush=True)


asyncio.run(main())

Agent(...) infers the provider from the model id. No tools are registered unless you pass tools=[...], and nothing is persisted unless you pass session_dir=.

For a synchronous call, use run() — it collects the stream into a RunResult:

result = agent.run("Read pyproject.toml and tell me the project name.")
print(result.text)

Call achat or run again on the same Agent to continue the conversation — history accumulates in agent.messages.

To persist across processes, pass session_dir as the root directory; each session_id becomes a subdirectory. Reconstruct with the same (session_dir, session_id) to resume.

Built-in tools

from mycode import read_tool, write_tool, edit_tool, bash_tool

Only bash_tool streams incremental output as tool_output events; the others return a single result.

Custom tools

@tool wraps a sync or async def Python function as a ToolSpec. Parameter type hints become the JSON schema sent to the provider.

Annotate the first parameter as ToolContext to have the context injected. Use ctx.read / ctx.write / ctx.edit / ctx.bash to invoke the built-ins, or ctx.call(name, args) for any registered tool by name.

from mycode import Agent, ToolContext, read_tool, tool


@tool
def summarize_file(ctx: ToolContext, path: str) -> str:
    """Return the first line of a text file."""

    result = ctx.read(path)
    return result.output.splitlines()[0] if result.output else ""


agent = Agent(
    model="claude-sonnet-4-6",
    api_key="YOUR_API_KEY",
    cwd=".",
    tools=[read_tool, summarize_file],
)

A bare str return becomes the tool output; any other JSON-serializable value is dumped to JSON. For finer control, return a ToolExecutionResult to set output, content (multimodal blocks such as images), metadata (structured UI data), and is_error independently.

See docs/sdk.md for the event stream, cancellation, session rules, and the full Agent / @tool reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mycode_sdk-0.5.1.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mycode_sdk-0.5.1-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

Details for the file mycode_sdk-0.5.1.tar.gz.

File metadata

  • Download URL: mycode_sdk-0.5.1.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mycode_sdk-0.5.1.tar.gz
Algorithm Hash digest
SHA256 1faca93b0917f139b2cdc74e98921e188f88dd9c3bfa2f9434d9c3cb8aeb1bbc
MD5 338a7e613781ccd0d4e9d739554dd14b
BLAKE2b-256 d226fe326067b9aba5052970c9002d7ae552a355558a57b66ea9a55d2466c335

See more details on using hashes here.

File details

Details for the file mycode_sdk-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: mycode_sdk-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 55.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mycode_sdk-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29c6b5a0ed20aa3b59f92d11c3b07eb5e46b35370c1eb7736694af752ac529e5
MD5 0da799f604929a15780e5a08da5950bf
BLAKE2b-256 d45c52a66043116d8c03464dc06a2ac24cf67b69e23bc7d63200207b79c22918

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page