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.0.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.0-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mycode_sdk-0.5.0.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.0.tar.gz
Algorithm Hash digest
SHA256 3bce3a076cb27cfac3652698911d5a71a6084291673b1ee839ab509257d1b33c
MD5 4c5ac2e25b7f227977c0b0d732101d2a
BLAKE2b-256 880de3b07fd90246fc5b536d2c83476832a1e166b84ce3fe38cca10ac7faa1ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mycode_sdk-0.5.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77442220b8167e5a2baf2f9025158fa0c1b19e62892fc0b8992459fb3044c75a
MD5 74d9d031095a9fe05540a658b3314dd7
BLAKE2b-256 4d924078b0866439a4f6e5b93aab4dda0b2eba7797920f3aa2dbbc9eccdb21c6

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