mycode-sdk 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mycode/__init__.py +72 -0
- mycode/agent.py +616 -0
- mycode/messages.py +182 -0
- mycode/models.py +161 -0
- mycode/models_catalog.json +2547 -0
- mycode/providers/__init__.py +86 -0
- mycode/providers/anthropic_like.py +387 -0
- mycode/providers/base.py +387 -0
- mycode/providers/gemini.py +316 -0
- mycode/providers/openai_chat.py +368 -0
- mycode/providers/openai_responses.py +372 -0
- mycode/py.typed +0 -0
- mycode/session.py +562 -0
- mycode/tools.py +1275 -0
- mycode/utils.py +38 -0
- mycode_sdk-0.4.2.dist-info/METADATA +114 -0
- mycode_sdk-0.4.2.dist-info/RECORD +19 -0
- mycode_sdk-0.4.2.dist-info/WHEEL +4 -0
- mycode_sdk-0.4.2.dist-info/licenses/LICENSE +21 -0
mycode/utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Shared utilities used across core modules."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def as_int(value: Any) -> int | None:
|
|
10
|
+
"""Return value if it is a strict int (not bool), otherwise None."""
|
|
11
|
+
return None if isinstance(value, bool) or not isinstance(value, int) else value
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def as_bool(value: Any) -> bool | None:
|
|
15
|
+
"""Return value if it is a bool, otherwise None."""
|
|
16
|
+
return value if isinstance(value, bool) else None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def omit_none(d: dict[str, Any]) -> dict[str, Any]:
|
|
20
|
+
"""Return a shallow copy of d with None values removed."""
|
|
21
|
+
return {k: v for k, v in d.items() if v is not None}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def parse_tool_arguments(raw: str | None) -> dict[str, Any] | str:
|
|
25
|
+
"""Parse a JSON tool-arguments string.
|
|
26
|
+
|
|
27
|
+
Returns the parsed dict, or an error string if the input is invalid.
|
|
28
|
+
Empty / None input is treated as an empty argument set.
|
|
29
|
+
"""
|
|
30
|
+
if not raw or not raw.strip():
|
|
31
|
+
return {}
|
|
32
|
+
try:
|
|
33
|
+
parsed = json.loads(raw)
|
|
34
|
+
except json.JSONDecodeError:
|
|
35
|
+
return "error: invalid JSON arguments"
|
|
36
|
+
if not isinstance(parsed, dict):
|
|
37
|
+
return "error: tool arguments must decode to a JSON object"
|
|
38
|
+
return parsed
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mycode-sdk
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Summary: Multi-turn tool-calling agent runtime for embedding the mycode agent loop.
|
|
5
|
+
Project-URL: Homepage, https://github.com/legibet/mycode
|
|
6
|
+
Project-URL: Repository, https://github.com/legibet/mycode
|
|
7
|
+
Project-URL: Issues, https://github.com/legibet/mycode/issues
|
|
8
|
+
Author-email: LeGibet <legibetpeng@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,anthropic,gemini,llm,openai,sdk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: anthropic>=0.74.0
|
|
22
|
+
Requires-Dist: google-genai>=1.68.0
|
|
23
|
+
Requires-Dist: openai>=2.11.0
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# mycode-sdk
|
|
27
|
+
|
|
28
|
+
Lightweight Python SDK for the mycode multi-turn tool-calling agent. Import name: `mycode`.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv add mycode-sdk
|
|
34
|
+
# or
|
|
35
|
+
pip install mycode-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
`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`.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import asyncio
|
|
44
|
+
|
|
45
|
+
from mycode import Agent, bash_tool, read_tool
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def main() -> None:
|
|
49
|
+
agent = Agent(
|
|
50
|
+
model="claude-sonnet-4-6",
|
|
51
|
+
api_key="YOUR_API_KEY",
|
|
52
|
+
cwd=".",
|
|
53
|
+
system="You are a concise coding assistant.",
|
|
54
|
+
tools=[read_tool, bash_tool],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
async for event in agent.achat("Read pyproject.toml and tell me the project name."):
|
|
58
|
+
if event.type == "text":
|
|
59
|
+
print(event.data["delta"], end="")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
asyncio.run(main())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To resume a previous conversation, pass the same `session_id` (the agent loads its own history from disk).
|
|
66
|
+
|
|
67
|
+
## Built-in tools
|
|
68
|
+
|
|
69
|
+
Pick and combine the four bundled coding tools:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from mycode import read_tool, write_tool, edit_tool, bash_tool
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Custom Tools
|
|
76
|
+
|
|
77
|
+
`@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.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from mycode import Agent, ToolContext, read_tool, tool
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@tool
|
|
84
|
+
def summarize_file(ctx: ToolContext, path: str) -> str:
|
|
85
|
+
"""Return the first line of a text file."""
|
|
86
|
+
|
|
87
|
+
result = ctx.call("read", {"path": path})
|
|
88
|
+
return result.model_text.splitlines()[0] if result.model_text else ""
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
agent = Agent(
|
|
92
|
+
model="claude-sonnet-4-6",
|
|
93
|
+
api_key="YOUR_API_KEY",
|
|
94
|
+
cwd=".",
|
|
95
|
+
tools=[read_tool, summarize_file],
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
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.
|
|
100
|
+
|
|
101
|
+
## Disabling auto-persistence
|
|
102
|
+
|
|
103
|
+
Point `session_dir` (or the implied `SessionStore` data dir) at a temporary directory if you need an ephemeral session:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import tempfile
|
|
107
|
+
from pathlib import Path
|
|
108
|
+
|
|
109
|
+
agent = Agent(
|
|
110
|
+
model="claude-sonnet-4-6",
|
|
111
|
+
cwd=".",
|
|
112
|
+
session_dir=Path(tempfile.mkdtemp()) / "scratch",
|
|
113
|
+
)
|
|
114
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
mycode/__init__.py,sha256=mH9wD-pKsJx8buBEmPMDYaSsKAValSlbDUXcoHss8wU,1804
|
|
2
|
+
mycode/agent.py,sha256=eCbZQg6nlNVfHYC6n8xhSlLtQGhsuAti0YeNV2F1Lgo,23141
|
|
3
|
+
mycode/messages.py,sha256=TTrEPyZ4ef0OcPtYeUpWdldBDa8vHKuoYqNNNyth6X0,5296
|
|
4
|
+
mycode/models.py,sha256=xoWldezejrpB6dzEJdbbOdfseEb4hxxcrIAE5ZQIFwY,5192
|
|
5
|
+
mycode/models_catalog.json,sha256=Cpmm9S2OeCr5koyFOo9zi31CFLqFCupan5BCBw0lb2I,75197
|
|
6
|
+
mycode/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
mycode/session.py,sha256=0d8jzkogys3pGe4JNB_6l-rSR2aP29mnRaYya0sSlbE,19528
|
|
8
|
+
mycode/tools.py,sha256=iKkc9dC7t2xQeZsuJYBxvo21nkvTSpUs-VAAp73YF-s,43985
|
|
9
|
+
mycode/utils.py,sha256=owQv38IWboxkF-7qcbWnkpMjK0susMRKX2QZLAznqKo,1196
|
|
10
|
+
mycode/providers/__init__.py,sha256=KQbLyTwhxrTUZBELYJtUtz6LVVHit02zjbWKwiIkG2Q,2777
|
|
11
|
+
mycode/providers/anthropic_like.py,sha256=Uah_QwkOmQR-JAdej4Gzrx5FuS_-3WrJLeplrkVAN2o,14948
|
|
12
|
+
mycode/providers/base.py,sha256=43Ykjos2cfcRkd1fBCXfeoAGRiiMk3FA9ky0zrMUGkk,14553
|
|
13
|
+
mycode/providers/gemini.py,sha256=wXaaDVxGOGscDdQcE56Am8theQO4bGg-MnMx1PP-BGo,13524
|
|
14
|
+
mycode/providers/openai_chat.py,sha256=xB5OJcGrXX6389cnbgaI_ptU8UNv3hKEQQ0r0sVvDw0,14737
|
|
15
|
+
mycode/providers/openai_responses.py,sha256=vp9jgI_NpI2ag33Hn8DcgAImaQ9f4_5hgAD-O8PFbrc,15426
|
|
16
|
+
mycode_sdk-0.4.2.dist-info/METADATA,sha256=Ozj0BpXiH9xkdMu4SP3I4mzjIVkdOkZRR7kzkli5VIM,3365
|
|
17
|
+
mycode_sdk-0.4.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
18
|
+
mycode_sdk-0.4.2.dist-info/licenses/LICENSE,sha256=DSE6T-B9WhrWypr6H7y2kTZzoF1tef5xf7veUyImQsM,1064
|
|
19
|
+
mycode_sdk-0.4.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LeGibet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|