Copass agent primitives for the Anthropic Managed Agents API
Project description
copass-anthropic-agents
Anthropic Managed Agents backend for Copass. Depends on copass-core-agents, which owns the vendor-neutral primitives (BaseAgent, AgentTool, AgentBackend ABC, events, AgentScope, registries, etc.) shared across every provider-specific Copass SDK.
This package owns the Anthropic-specific piece — ManagedAgentBackend and the CopassManagedAgent convenience subclass — and re-exports the core primitives for one-line dev imports. Either of these works for consumers:
from copass_anthropic_agents import BaseAgent, CopassManagedAgent # convenient
# or
from copass_core_agents import BaseAgent # explicit boundary
from copass_anthropic_agents import CopassManagedAgent
Pairs with Copass's server-side router — both sides import the same code so the agent runtime is a single codepath, whether the agent runs in the dev's process (deep-integration) or server-side via Copass's Router endpoint (thin client).
Install
pip install copass-anthropic-agents
Requires anthropic>=0.93.0 (first version shipping the beta.agents / beta.environments / beta.sessions surface).
Quickstart
import os
from copass_anthropic_agents import (
AgentInvocationContext,
AgentScope,
CopassManagedAgent,
)
agent = CopassManagedAgent(
identity="support",
system_prompt="You are a support agent.",
anthropic_api_key=os.environ["ANTHROPIC_API_KEY"],
)
ctx = AgentInvocationContext(scope=AgentScope(user_id="u-123"))
result = await agent.run(
messages=[{"role": "user", "content": "Hello"}],
context=ctx,
)
print(result.final_text)
Streaming
from copass_anthropic_agents import (
AgentFinish,
AgentTextDelta,
AgentToolCall,
AgentToolResult,
)
async for evt in agent.stream(messages, context=ctx):
match evt:
case AgentTextDelta(text=chunk):
print(chunk, end="", flush=True)
case AgentToolCall(name=name, arguments=args):
print(f"\n[tool-call] {name}")
case AgentToolResult(name=name, result=result):
print(f"\n[tool-result] {name}")
case AgentFinish(stop_reason=reason, session_id=sid):
print(f"\n[finish] {reason} session={sid}")
Multi-turn continuation
The Anthropic managed-agent session holds conversation state. Capture AgentFinish.session_id and thread it back on the next turn:
from copass_anthropic_agents import SESSION_ID_HANDLE
ctx2 = AgentInvocationContext(
scope=AgentScope(user_id="u-123"),
handles={SESSION_ID_HANDLE: prior_session_id},
)
Custom tools
See AgentTool + AgentToolRegistry + AgentToolResolver. Tools are dispatched locally on tool-use events; provider handles the rest.
from copass_anthropic_agents import AgentTool, AgentToolRegistry, ToolSpec
class EchoTool(AgentTool):
@property
def spec(self):
return ToolSpec(
name="echo",
description="Echo a message back.",
input_schema={
"type": "object",
"properties": {"text": {"type": "string"}},
"required": ["text"],
},
)
async def invoke(self, arguments, *, context=None):
return {"echoed": arguments["text"]}
tools = AgentToolRegistry()
tools.add(EchoTool())
agent = CopassManagedAgent(
identity="support",
system_prompt="You are helpful.",
anthropic_api_key=os.environ["ANTHROPIC_API_KEY"],
tools=tools,
)
Rate-limit note
ManagedAgentBackend caches Anthropic-side agent + environment resources per-instance by a fingerprint of (model, system_prompt, tool_schemas). Reusing the backend across requests shares the cache; constructing a fresh backend per request re-creates resources and hits Anthropic's 60-creates/min limit fast. Use the backend as a process-wide singleton in server contexts.
Context injection (deferred)
A future release will pull Copass's Context Window into system_prompt via the reserved {{copass_context}} placeholder (see spec/context-placeholders.md in this monorepo). Not wired in this release — injection would change system_prompt per invocation, invalidating the backend's fingerprint cache.
License
MIT.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copass_anthropic_agents-0.4.3.tar.gz.
File metadata
- Download URL: copass_anthropic_agents-0.4.3.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d60ac1e6f837c991a57097068bdf48f227a7655e57c4c71da61cb13bf9f95d08
|
|
| MD5 |
67d690bd44bf9e85155e965381824cb7
|
|
| BLAKE2b-256 |
c7b3495577ca2bedac27b64b27f40ff2585772b4764945c052c59351b9d2ed81
|
Provenance
The following attestation bundles were made for copass_anthropic_agents-0.4.3.tar.gz:
Publisher:
release-python.yml on olane-labs/copass-harness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copass_anthropic_agents-0.4.3.tar.gz -
Subject digest:
d60ac1e6f837c991a57097068bdf48f227a7655e57c4c71da61cb13bf9f95d08 - Sigstore transparency entry: 1398178378
- Sigstore integration time:
-
Permalink:
olane-labs/copass-harness@3f5a7071ab330f00193c87900ede94a74ddc4a42 -
Branch / Tag:
refs/heads/production - Owner: https://github.com/olane-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@3f5a7071ab330f00193c87900ede94a74ddc4a42 -
Trigger Event:
push
-
Statement type:
File details
Details for the file copass_anthropic_agents-0.4.3-py3-none-any.whl.
File metadata
- Download URL: copass_anthropic_agents-0.4.3-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a80be61c4afe234cb1413239de9ecf227ebea1bd3c7073b5a8d9ebe22c63be71
|
|
| MD5 |
e2bb2a9b82a706ca7818875c3c6f08b3
|
|
| BLAKE2b-256 |
53cd4f0d17e58436858b3cb3661da82aa058c5db5eddf505ff8a1a521ebbe555
|
Provenance
The following attestation bundles were made for copass_anthropic_agents-0.4.3-py3-none-any.whl:
Publisher:
release-python.yml on olane-labs/copass-harness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copass_anthropic_agents-0.4.3-py3-none-any.whl -
Subject digest:
a80be61c4afe234cb1413239de9ecf227ebea1bd3c7073b5a8d9ebe22c63be71 - Sigstore transparency entry: 1398178403
- Sigstore integration time:
-
Permalink:
olane-labs/copass-harness@3f5a7071ab330f00193c87900ede94a74ddc4a42 -
Branch / Tag:
refs/heads/production - Owner: https://github.com/olane-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@3f5a7071ab330f00193c87900ede94a74ddc4a42 -
Trigger Event:
push
-
Statement type: