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",
        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 and defaults cwd to the current working directory. 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",
    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.2.tar.gz (47.0 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.2-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mycode_sdk-0.5.2.tar.gz
  • Upload date:
  • Size: 47.0 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.2.tar.gz
Algorithm Hash digest
SHA256 eb9c4d4a88de93c25e0d023f1d9c0113935170b0a9f3453168fb7d66e24d284b
MD5 0dc3126c43807e8a6f8364d5d0514518
BLAKE2b-256 4c29ff958cdf956de40bc1f8f480161ecec7b75d1bb300f77fb8cda0016e2268

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mycode_sdk-0.5.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 409fe8aa45542df778973a5fcc493735fcb2aca7e8595fd60f267951a0ac1f6f
MD5 75fa5b8a6889a92e7449a21967741ac3
BLAKE2b-256 a9b95ceaaf889cb2f68018573542920aaf10abf79bdb2a93300409c76b7b747d

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