Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any

from acp import (
PROTOCOL_VERSION,
Agent,
AgentSideConnection,
AuthenticateResponse,
InitializeResponse,
LoadSessionResponse,
Expand All @@ -14,7 +14,6 @@
run_agent,
text_block,
update_agent_message,
PROTOCOL_VERSION,
)
from acp.interfaces import Client
from acp.schema import (
Expand Down
8 changes: 4 additions & 4 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from typing import Any

from acp import (
PROTOCOL_VERSION,
Client,
connect_to_agent,
RequestError,
connect_to_agent,
text_block,
PROTOCOL_VERSION,
)
from acp.core import ClientSideConnection
from acp.schema import (
Expand Down Expand Up @@ -154,8 +154,8 @@ async def interactive_loop(conn: ClientSideConnection, session_id: str) -> None:
session_id=session_id,
prompt=[text_block(line)],
)
except Exception as exc: # noqa: BLE001
logging.error("Prompt failed: %s", exc)
except Exception as exc:
logging.error("Prompt failed: %s", exc) # noqa: TRY400


async def main(argv: list[str]) -> int:
Expand Down
6 changes: 2 additions & 4 deletions examples/duet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sys
from pathlib import Path

from acp import PROTOCOL_VERSION, spawn_agent_process


def _load_client_module(path: Path):
spec = importlib.util.spec_from_file_location("examples_client", path)
Expand All @@ -15,10 +17,6 @@ def _load_client_module(path: Path):
return module


from acp import PROTOCOL_VERSION, spawn_agent_process
from acp.schema import InitializeRequest, NewSessionRequest


async def main() -> int:
root = Path(__file__).resolve().parent
agent_path = root / "agent.py"
Expand Down
1 change: 0 additions & 1 deletion examples/echo_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from acp import (
Agent,
AgentSideConnection,
InitializeResponse,
NewSessionResponse,
PromptResponse,
Expand Down
31 changes: 14 additions & 17 deletions examples/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import os
import shutil
import sys
from collections.abc import Iterable
from pathlib import Path
from typing import Any, Iterable
from typing import Any

from acp import (
Client,
connect_to_agent,
PROTOCOL_VERSION,
Client,
RequestError,
connect_to_agent,
text_block,
)
from acp.core import ClientSideConnection
Expand All @@ -25,26 +26,22 @@
AgentThoughtChunk,
AllowedOutcome,
AvailableCommandsUpdate,
CancelNotification,
ClientCapabilities,
CreateTerminalResponse,
CurrentModeUpdate,
DeniedOutcome,
EmbeddedResourceContentBlock,
EnvVariable,
FileEditToolCallContent,
FileSystemCapability,
CreateTerminalResponse,
DeniedOutcome,
EmbeddedResourceContentBlock,
KillTerminalCommandResponse,
InitializeRequest,
NewSessionRequest,
PermissionOption,
PromptRequest,
ReadTextFileResponse,
ReleaseTerminalResponse,
RequestPermissionResponse,
ResourceContentBlock,
ReleaseTerminalResponse,
TerminalToolCallContent,
TerminalOutputResponse,
TerminalToolCallContent,
TextContentBlock,
ToolCall,
ToolCallProgress,
Expand Down Expand Up @@ -115,7 +112,7 @@ async def read_text_file(
text = _slice_text(text, line, limit)
return ReadTextFileResponse(content=text)

async def session_update(
async def session_update( # noqa: C901
self,
session_id: str,
update: UserMessageChunk
Expand Down Expand Up @@ -259,7 +256,7 @@ async def interactive_loop(conn: ClientSideConnection, session_id: str) -> None:
)
except RequestError as err:
_print_request_error("prompt", err)
except Exception as exc: # noqa: BLE001
except Exception as exc:
print(f"Prompt failed: {exc}", file=sys.stderr)


Expand All @@ -275,7 +272,7 @@ def _resolve_gemini_cli(binary: str | None) -> str:
raise FileNotFoundError("Unable to locate `gemini` CLI, provide --gemini path")


async def run(argv: list[str]) -> int:
async def run(argv: list[str]) -> int: # noqa: C901
parser = argparse.ArgumentParser(description="Interact with the Gemini CLI over ACP.")
parser.add_argument("--gemini", help="Path to the Gemini CLI binary")
parser.add_argument("--model", help="Model identifier to pass to Gemini")
Expand Down Expand Up @@ -331,7 +328,7 @@ async def run(argv: list[str]) -> int:
_print_request_error("initialize", err)
await _shutdown(proc, conn)
return 1
except Exception as exc: # noqa: BLE001
except Exception as exc:
print(f"initialize error: {exc}", file=sys.stderr)
await _shutdown(proc, conn)
return 1
Expand All @@ -347,7 +344,7 @@ async def run(argv: list[str]) -> int:
_print_request_error("new_session", err)
await _shutdown(proc, conn)
return 1
except Exception as exc: # noqa: BLE001
except Exception as exc:
print(f"new_session error: {exc}", file=sys.stderr)
await _shutdown(proc, conn)
return 1
Expand Down
18 changes: 11 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name = "agent-client-protocol"
version = "0.6.3"
description = "A Python implement of Agent Client Protocol (ACP, by Zed Industries)"
authors = [{ name = "Chojan Shang", email = "psiace@apache.org" }]
authors = [
{ name = "Chojan Shang", email = "psiace@apache.org" },
{ name = "Frost Ming", email = "me@frostming.com" },
]
readme = "README.md"
keywords = ['python']
requires-python = ">=3.10,<3.15"
Expand All @@ -18,7 +21,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"pydantic>=2.7",
"pydantic>=2.7",
]


Expand Down Expand Up @@ -47,11 +50,11 @@ dev = [
logfire = ["logfire>=0.14", "opentelemetry-sdk>=1.28.0"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.hatch.build.targets.wheel]
packages = ["src/acp"]
[tool.pdm.build]
source-includes = ["examples/", "tests/"]

[tool.ty.environment]
python = "./.venv"
Expand Down Expand Up @@ -103,11 +106,12 @@ ignore = [
"E501",
# DoNotAssignLambda
"E731",
# Long exception message
"TRY003",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]
"examples/*" = ["ALL"]
"src/acp/meta.py" = ["ALL"]
"src/acp/schema.py" = ["ALL"]

Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def fetch_json(url: str) -> dict:
with urllib.request.urlopen(url) as response: # noqa: S310 - trusted source configured by repo
return json.loads(response.read().decode("utf-8"))
except urllib.error.URLError as exc:
raise RuntimeError(f"Failed to fetch {url}: {exc}") from exc # noqa: TRY003
raise RuntimeError(f"Failed to fetch {url}: {exc}") from exc


def _cached_ref() -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def generate_meta() -> None:
meta_json = SCHEMA_DIR / "meta.json"
out_py = ROOT / "src" / "acp" / "meta.py"
if not meta_json.exists():
raise SystemExit("schema/meta.json not found. Run gen_schema.py first.") # noqa: TRY003
raise SystemExit("schema/meta.json not found. Run gen_schema.py first.")

data = json.loads(meta_json.read_text("utf-8"))
agent_methods = data.get("agentMethods", {})
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def generate_schema() -> None:

def postprocess_generated_schema(output_path: Path) -> list[str]:
if not output_path.exists():
raise RuntimeError(f"Generated schema not found at {output_path}") # noqa: TRY003
raise RuntimeError(f"Generated schema not found at {output_path}")

raw_content = output_path.read_text(encoding="utf-8")
header_block = _build_header_block()
Expand Down
2 changes: 1 addition & 1 deletion src/acp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ def __getattr__(name: str) -> Any:
module_name, attr_name = new_path.split(":")
module = import_module(module_name)
return getattr(module, attr_name)
raise AttributeError(f"module {__name__} has no attribute {name}") # noqa: TRY003
raise AttributeError(f"module {__name__} has no attribute {name}")