Skip to main content

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

Project description

mycode-sdk

Lightweight Python SDK for the mycode multi-turn tool-calling agent. Import name: mycode.

Install

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

Quick Start

Agent(...) fills in sensible defaults: provider inferred from the model id, session_id generated, session log auto-persisted to ~/.mycode/sessions/<session_id>/. By default no tools are registered — pick the built-ins you want or register your own via @tool.

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=".",
        system="You are a concise coding assistant.",
        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="")


asyncio.run(main())

To resume a previous conversation, pass the same session_id (the agent loads its own history from disk).

Built-in tools

Pick and combine the four bundled coding tools:

from mycode import read_tool, write_tool, edit_tool, bash_tool

Custom Tools

@tool wraps a plain Python function (sync or async) as a ToolSpec. If the first parameter is annotated ToolContext, the context is injected; use ctx.call("read", {...}) to invoke another registered tool.

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.call("read", {"path": path})
    return result.model_text.splitlines()[0] if result.model_text else ""


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

Type hints drive the JSON schema. Unknown types raise; missing docstrings raise. async def tools are run via asyncio.run on the executor's worker thread.

Disabling auto-persistence

Point session_dir (or the implied SessionStore data dir) at a temporary directory if you need an ephemeral session:

import tempfile
from pathlib import Path

agent = Agent(
    model="claude-sonnet-4-6",
    cwd=".",
    session_dir=Path(tempfile.mkdtemp()) / "scratch",
)

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.4.2.tar.gz (46.2 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.4.2-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mycode_sdk-0.4.2.tar.gz
  • Upload date:
  • Size: 46.2 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.4.2.tar.gz
Algorithm Hash digest
SHA256 88a57c9573033e4307b60cba9aa650c78f60aa28ec4c7453b5ee975d45845f4b
MD5 7d8f855fce91dc3ad2ef73244d1a6278
BLAKE2b-256 1a24718dc3fb52957d0dcec3bcb5878298afbbbcdd20a9a166b9705908989f80

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mycode_sdk-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 54.3 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.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1309f78cebd65e9e45672b04c92f58124cc8fe9bf3da8a03a739c506b53b3df7
MD5 e4d56ad6e9132e6b7af5fd0cf952e7b5
BLAKE2b-256 25fef1bbe82c240a32efa4fc58379784b9f0dfd7c79a079508ff93c2bf672a1f

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