Claude API¶
Claude Minions use Anthropic's native beta tool runners for complete hosted and local tool workflows.
claude
¶
Assembly: minions Filename: claude.py Author: Terry D. Eppler Created: 09-05-2026
Last Modified By: Terry D. Eppler Last Modified On: 09-06-2026
claude.py
Copyright © 2026 Terry D. Eppler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov
SyncAdapter(tool: BetaFunctionTool)
¶
Bases: BetaFunctionTool
Native synchronous tool adapter.
Purpose
Uses the original Anthropic tool's validated call and declaration, converting only its return value at the provider result boundary.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
BetaFunctionTool
|
Original native synchronous tool. |
Initialize the native synchronous adapter.
Purpose
Retains the original callable and schema without modifying the supplied tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
BetaFunctionTool
|
Original native synchronous tool. |
required |
Source code in claude.py
to_dict() -> BetaToolParam
¶
Return the original provider declaration.
Purpose
Preserves native schema and additional provider declaration metadata.
Returns:
| Name | Type | Description |
|---|---|---|
BetaToolParam |
BetaToolParam
|
Original native tool declaration. |
Source code in claude.py
call(input: object) -> str | list[Content]
¶
Execute the original validated tool.
Purpose
Delegates input validation and execution to the original native tool and converts the result. Tool failures propagate to the native runner for error-result handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
object
|
Model-generated tool arguments; an empty dictionary is valid. |
required |
Returns:
| Type | Description |
|---|---|
str | list[Content]
|
str | list[Content]: Provider-compatible result content. |
Source code in claude.py
AsyncAdapter(tool: BetaFunctionTool)
¶
Bases: BetaAsyncFunctionTool
Native asynchronous adapter for synchronous Anthropic tools.
Purpose
Executes the original validated tool in a worker thread without defining a variadic callback or changing the original tool declaration.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
BetaFunctionTool
|
Original native synchronous tool. |
Initialize the native asynchronous adapter.
Purpose
Binds the explicit async call interface and retains the original schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
BetaFunctionTool
|
Original native synchronous tool. |
required |
Source code in claude.py
to_dict() -> BetaToolParam
¶
Return the original provider declaration.
Purpose
Preserves native schema and additional provider declaration metadata.
Returns:
| Name | Type | Description |
|---|---|---|
BetaToolParam |
BetaToolParam
|
Original native tool declaration. |
Source code in claude.py
call(input: object) -> str | list[Content]
async
¶
Execute the original validated tool asynchronously.
Purpose
Delegates validation and execution to the original native tool without blocking the event loop. Tool failures propagate to the native runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
object
|
Model-generated tool arguments; an empty dictionary is valid. |
required |
Returns:
| Type | Description |
|---|---|
str | list[Content]
|
str | list[Content]: Provider-compatible result content. |
Source code in claude.py
Minion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Claude workflow agent backed by Anthropic's native Tool Runner.
Purpose
Executes synchronous, asynchronous and streamed Claude workflows with caller-selected native tools, centralized credentials and the provider-managed tool lifecycle.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default specialization name. |
name |
str
|
Agent display name. |
model |
str
|
Claude model identifier. |
instructions |
str
|
System instructions. |
tools |
list[ClaudeTool]
|
Original caller-selected tools. |
sync_tools |
list[ClaudeTool]
|
Native synchronous runner tools. |
async_tools |
list[ClaudeAsyncTool]
|
Native asynchronous runner tools. |
max_turns |
int
|
Maximum model iterations per execution. |
max_tokens |
int
|
Maximum output tokens per iteration. |
api_key |
str
|
Centralized Anthropic credential. |
client |
Anthropic
|
Native synchronous client. |
async_client |
AsyncAnthropic
|
Native asynchronous client. |
prompt |
str
|
Most recently accepted user prompt. |
tool |
BetaFunctionTool | None
|
Most recently accepted public adapter argument. |
result |
BetaMessage | BetaAsyncStreamingToolRunner[object] | None
|
Native execution result. |
Initialize a Claude Minion.
Purpose
Stores configuration, initializes native clients and adapts local tools for the respective runner without modifying the original tool objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Nonblank Claude model identifier. |
required |
instructions
|
str
|
Nonblank system instructions. |
required |
tools
|
Sequence[ClaudeTool] | None
|
Optional native local or hosted tools. |
None
|
max_turns
|
int
|
Positive iteration limit; defaults to 10. |
10
|
max_tokens
|
int
|
Positive output token limit; defaults to 4096. |
4096
|
name
|
str | None
|
Optional nonblank display name overriding the specialization. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If required strings, credentials or positive limits are invalid. |
TypeError
|
If tools is not an appropriate sequence. |
Source code in claude.py
create_async_tool(tool: BetaFunctionTool) -> BetaAsyncFunctionTool
¶
Create a native asynchronous adapter.
Purpose
Retains the original tool schema and validated execution contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
BetaFunctionTool
|
Synchronous native Anthropic tool. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BetaAsyncFunctionTool |
BetaAsyncFunctionTool
|
Native asynchronous tool adapter. |
Raises:
| Type | Description |
|---|---|
Error
|
If argument validation or adapter construction fails. |
Source code in claude.py
run(prompt: str) -> BetaMessage
¶
Execute the complete Claude workflow synchronously.
Purpose
Delegates the complete model and local tool execution loop to Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Nonblank user input for the workflow. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BetaMessage |
BetaMessage
|
Native completed message. |
Raises:
| Type | Description |
|---|---|
Error
|
If validation or the native runner execution fails. |
Source code in claude.py
run_async(prompt: str) -> BetaMessage
async
¶
Execute the complete Claude workflow asynchronously.
Purpose
Delegates the complete model and local tool execution loop to Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Nonblank user input for the workflow. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BetaMessage |
BetaMessage
|
Native completed message. |
Raises:
| Type | Description |
|---|---|
Error
|
If validation or the native runner execution fails. |
Source code in claude.py
stream(prompt: str) -> BetaAsyncStreamingToolRunner[object]
¶
Start the native async streaming runner.
Purpose
Returns the native streaming runner for caller-managed consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Nonblank user input for the workflow. |
required |
Returns:
| Type | Description |
|---|---|
BetaAsyncStreamingToolRunner[object]
|
BetaAsyncStreamingToolRunner[ object ]: Native streaming runner. |
Raises:
| Type | Description |
|---|---|
Error
|
If validation or the native runner creation fails. |
Source code in claude.py
DataMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for data workflows.
Purpose
Provides the named data agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
GovernanceMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for governance workflows.
Purpose
Provides the named governance agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
ResearchMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for research workflows.
Purpose
Provides the named research agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
CodingMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for software workflows.
Purpose
Provides the named software agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
WritingMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for writing workflows.
Purpose
Provides the named writing agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
PlanningMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for planning workflows.
Purpose
Provides the named planning agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
ComplianceMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for compliance, legal, and budget workflows.
Purpose
Provides the named compliance, legal, and budget agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
BusinessMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for business, finance, and marketing workflows.
Purpose
Provides the named business, finance, and marketing agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
ImageGenerationMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for image-generation workflows.
Purpose
Provides the named image-generation agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
ImageAnalysisMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for image-analysis workflows.
Purpose
Provides the named image-analysis agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
ImageEditingMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for image-editing workflows.
Purpose
Provides the named image-editing agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
TranslationMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for translation workflows.
Purpose
Provides the named translation agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
TranscriptionMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for transcription workflows.
Purpose
Provides the named transcription agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
SpeechMinion(model: str, instructions: str, tools: Sequence[ClaudeTool] | None = None, max_turns: int = 10, max_tokens: int = 4096, name: str | None = None)
¶
Bases: Minion
Claude Minion specialized for speech workflows.
Purpose
Provides the named speech agent specialization while inheriting the native provider execution contract and caller-selected tools from Minion.
Attributes:
| Name | Type | Description |
|---|---|---|
minion_name |
str
|
Default display name for this specialization. |
Source code in claude.py
serialize_result(result: object) -> str | list[Content]
¶
Convert a local tool result for the Anthropic Tool Runner.
Purpose
Preserves native text and content-block collections and serializes structured Python values as JSON text. Null, false, zero and empty collections remain legitimate results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
object
|
Value returned by the selected local tool, including None. |
required |
Returns:
| Type | Description |
|---|---|
str | list[Content]
|
str | list[Content]: Anthropic-compatible tool-result content. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If an unsupported structured value is returned. |
ValueError
|
If the value cannot be encoded as valid JSON. |