execution
¤
Execution runtime models for CrewMaster v2.0.0.
| MODULE | DESCRIPTION |
|---|---|
drivers |
Runtime driver implementations for CrewMaster v2.0.0. |
retry |
Secure retry execution for CrewMaster v2.0.0. |
retry_test |
Tests for secure_retry_execution. |
runtime |
Runtime SPI models for CrewMaster v2.0.0. |
runtime_test |
Tests for Runtime SPI models. |
| CLASS | DESCRIPTION |
|---|---|
LangChainDriver |
Runtime driver backed by LangChain and LangGraph. |
PydanticAIDriver |
Runtime driver backed by PydanticAI. |
RuntimeDriver |
Protocol for runtime drivers that execute operations against LLMs. |
RuntimeRequest |
A request to execute an operation node against a runtime driver. |
RuntimeResponse |
The response from a runtime driver after executing a node. |
RuntimeStreamChunk |
A streaming event emitted during multi-node execution. |
TokenUsage |
Token usage for a single runtime invocation. |
| FUNCTION | DESCRIPTION |
|---|---|
secure_retry_execution |
Execute an async driver call with validation retries. |
__all__
module-attribute
¤
__all__ = ['LangChainDriver', 'PydanticAIDriver', 'RuntimeDriver', 'RuntimeRequest', 'RuntimeResponse', 'RuntimeStreamChunk', 'TokenUsage', 'secure_retry_execution']
LangChainDriver
¤
LangChainDriver(llm: BaseChatModel)
Runtime driver backed by LangChain and LangGraph.
Encapsulates the brain-muscle loop (BrainBase, MuscleBase,
graph nodes start, brain_node, muscle_node, cleaner)
behind the CrewMaster Runtime SPI.
The driver takes an LLM directly (not through RunnableConfig) and
tool schemas from RuntimeRequest.tools.
| ATTRIBUTE | DESCRIPTION |
|---|---|
llm |
The LangChain chat model instance.
|
| PARAMETER | DESCRIPTION |
|---|---|
|
A LangChain
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node via the brain-muscle loop. |
astream |
Execute a single node with streaming through the brain-muscle loop. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node via the brain-muscle loop.
Constructs a LangGraph graph, feeds it the runtime request,
runs the brain-muscle loop, and returns a RuntimeResponse.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
A |
RuntimeResponse
|
and raw messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming through the brain-muscle loop.
Streams LLM output token-by-token. If tool calls are present in a complete response, the driver executes them and re-enters the loop non-streamed, then resumes streaming for the next brain call.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
|
AsyncIterator[RuntimeStreamChunk]
|
|
PydanticAIDriver
¤
PydanticAIDriver(model_name: str = 'openai:gpt-4o', default_model_settings: dict[str, Any] | None = None)
Runtime driver backed by PydanticAI.
Constructs a PydanticAI Agent from each RuntimeRequest and executes it, returning structured output through the CrewMaster Runtime SPI.
| ATTRIBUTE | DESCRIPTION |
|---|---|
model_name |
The model name (or KnownModelName) to use by default.
|
default_model_settings |
Optional default settings (temperature, etc.).
|
| PARAMETER | DESCRIPTION |
|---|---|
|
Default model to use (can be overridden per-request
via
TYPE:
|
|
Default settings like temperature, top_p, etc. |
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node using PydanticAI. |
astream |
Execute a single node with streaming output using PydanticAI. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node using PydanticAI.
Constructs an Agent from the request, runs it, and returns a RuntimeResponse with the structured output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
RuntimeResponse with structured output, token usage, and messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming output using PydanticAI.
Yields RuntimeStreamChunk events (text_delta, tool_call, tool_result, final) as the agent produces output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
RuntimeStreamChunk events during agent execution. |
RuntimeDriver
¤
Protocol for runtime drivers that execute operations against LLMs.
Every runtime driver (PydanticAI, LangChain, etc.) must implement this
protocol. CrewMaster injects drivers per-agent via AgentConfig.runtime,
with a fallback to the default_runtime passed to execute().
Usage::
class PydanticAIDriver:
async def execute(self, request: RuntimeRequest) -> RuntimeResponse:
...
async def astream(
self, request: RuntimeRequest
) -> AsyncIterator[RuntimeStreamChunk]:
...
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node synchronously (from the caller's perspective). |
astream |
Execute a single node with streaming output. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node synchronously (from the caller's perspective).
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
A RuntimeResponse with the structured output. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
RuntimeStreamChunk events as the LLM produces output. |
RuntimeRequest
¤
A request to execute an operation node against a runtime driver.
| ATTRIBUTE | DESCRIPTION |
|---|---|
instructions |
The fully assembled and rendered prompt text.
TYPE:
|
tools |
The list of tool schemas visible to this node. |
context |
Resolved context dictionary for template variables. |
output_schema |
The Pydantic model type that the output must conform to.
TYPE:
|
runtime_hints |
Arbitrary driver-specific hints (model name, temp, etc.). |
conversation_history |
Previous messages for multi-turn execution. |
RuntimeResponse
¤
The response from a runtime driver after executing a node.
| ATTRIBUTE | DESCRIPTION |
|---|---|
output |
The structured output parsed into the requested schema (or None).
TYPE:
|
token_usage |
Token accounting for this invocation.
TYPE:
|
raw_messages |
The raw message list from the LLM provider. |
state |
Arbitrary driver state that may be needed downstream. |
token_usage
class-attribute
instance-attribute
¤
token_usage: TokenUsage = Field(default_factory=TokenUsage)
raw_messages
class-attribute
instance-attribute
¤
RuntimeStreamChunk
¤
A streaming event emitted during multi-node execution.
This is a discriminated union keyed on kind. Each kind carries
a different set of populated fields.
| ATTRIBUTE | DESCRIPTION |
|---|---|
kind |
The event type.
TYPE:
|
content |
Text delta content (for
TYPE:
|
tool_name |
Name of the tool being called (for
TYPE:
|
tool_args |
Arguments for the tool call (for |
tool_output |
Output from a tool execution (for
TYPE:
|
output |
The final parsed output model (for
TYPE:
|
node_name |
The name of the completed node (for
TYPE:
|
artifact |
The intermediate artifact from the node (for
TYPE:
|
TokenUsage
¤
Token usage for a single runtime invocation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
input_tokens |
Number of tokens consumed by the input (prompt).
TYPE:
|
output_tokens |
Number of tokens generated by the output.
TYPE:
|
secure_retry_execution
async
¤
secure_retry_execution(func: RetryFunc, max_attempts: int = 5, delay_seconds: float = 1.0, output_schema: type[BaseModel] | None = None) -> RuntimeResponse
Execute an async driver call with validation retries.
If output_schema is provided, the function validates that the
runtime response output conforms to the schema. On validation failure,
the error detail is recorded and an exception is raised so the caller
(typically the plan executor) can retry with error feedback injected
into the next request's instructions.
| PARAMETER | DESCRIPTION |
|---|---|
|
Async callable that returns a RuntimeResponse (driver call).
TYPE:
|
|
Maximum number of attempts before giving up.
TYPE:
|
|
Delay (in seconds) between retry attempts.
TYPE:
|
|
Optional Pydantic model to validate the output against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
The RuntimeResponse from a successful attempt. |
| RAISES | DESCRIPTION |
|---|---|
RetryExhaustedError
|
If all attempts are exhausted. |
ValidationError
|
If output_schema validation fails on the last attempt and the error is not wrapped. |
drivers
¤
Runtime driver implementations for CrewMaster v2.0.0.
| MODULE | DESCRIPTION |
|---|---|
langchain |
LangChain runtime driver for CrewMaster v2.0.0. |
langchain_test |
Tests for the LangChain runtime driver. |
pydantic_ai |
PydanticAI runtime driver for CrewMaster v2.0.0. |
pydantic_ai_test |
Tests for the PydanticAI runtime driver. |
| CLASS | DESCRIPTION |
|---|---|
LangChainDriver |
Runtime driver backed by LangChain and LangGraph. |
PydanticAIDriver |
Runtime driver backed by PydanticAI. |
LangChainDriver
¤
LangChainDriver(llm: BaseChatModel)
Runtime driver backed by LangChain and LangGraph.
Encapsulates the brain-muscle loop (BrainBase, MuscleBase,
graph nodes start, brain_node, muscle_node, cleaner)
behind the CrewMaster Runtime SPI.
The driver takes an LLM directly (not through RunnableConfig) and
tool schemas from RuntimeRequest.tools.
| ATTRIBUTE | DESCRIPTION |
|---|---|
llm |
The LangChain chat model instance.
|
| PARAMETER | DESCRIPTION |
|---|---|
|
A LangChain
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node via the brain-muscle loop. |
astream |
Execute a single node with streaming through the brain-muscle loop. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node via the brain-muscle loop.
Constructs a LangGraph graph, feeds it the runtime request,
runs the brain-muscle loop, and returns a RuntimeResponse.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
A |
RuntimeResponse
|
and raw messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming through the brain-muscle loop.
Streams LLM output token-by-token. If tool calls are present in a complete response, the driver executes them and re-enters the loop non-streamed, then resumes streaming for the next brain call.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
|
AsyncIterator[RuntimeStreamChunk]
|
|
PydanticAIDriver
¤
PydanticAIDriver(model_name: str = 'openai:gpt-4o', default_model_settings: dict[str, Any] | None = None)
Runtime driver backed by PydanticAI.
Constructs a PydanticAI Agent from each RuntimeRequest and executes it, returning structured output through the CrewMaster Runtime SPI.
| ATTRIBUTE | DESCRIPTION |
|---|---|
model_name |
The model name (or KnownModelName) to use by default.
|
default_model_settings |
Optional default settings (temperature, etc.).
|
| PARAMETER | DESCRIPTION |
|---|---|
|
Default model to use (can be overridden per-request
via
TYPE:
|
|
Default settings like temperature, top_p, etc. |
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node using PydanticAI. |
astream |
Execute a single node with streaming output using PydanticAI. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node using PydanticAI.
Constructs an Agent from the request, runs it, and returns a RuntimeResponse with the structured output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
RuntimeResponse with structured output, token usage, and messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming output using PydanticAI.
Yields RuntimeStreamChunk events (text_delta, tool_call, tool_result, final) as the agent produces output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
RuntimeStreamChunk events during agent execution. |
langchain
¤
LangChain runtime driver for CrewMaster v2.0.0.
Implements the RuntimeDriver protocol by refactoring the existing
brain-muscle loop into a LangGraph-backed driver. The driver encapsulates
the BrainBase, MuscleBase, and graph node logic behind the
standard execute(request) -> response interface.
Key adaptations:
- _build_messages_for_llm() receives RuntimeRequest instead of BrainInput.
- _parse_actions() returns RuntimeResponse instead of BrainOutput.
- Helper functions (_convert_to_tool_call, _convert_to_tool_message,
_is_skill_available, _is_response_structured,
_convert_action_to_computation, _ensure_dict) are internalized as
private methods.
| CLASS | DESCRIPTION |
|---|---|
LangChainDriver |
Runtime driver backed by LangChain and LangGraph. |
LangChainDriver
¤
LangChainDriver(llm: BaseChatModel)
Runtime driver backed by LangChain and LangGraph.
Encapsulates the brain-muscle loop (BrainBase, MuscleBase,
graph nodes start, brain_node, muscle_node, cleaner)
behind the CrewMaster Runtime SPI.
The driver takes an LLM directly (not through RunnableConfig) and
tool schemas from RuntimeRequest.tools.
| ATTRIBUTE | DESCRIPTION |
|---|---|
llm |
The LangChain chat model instance.
|
| PARAMETER | DESCRIPTION |
|---|---|
|
A LangChain
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node via the brain-muscle loop. |
astream |
Execute a single node with streaming through the brain-muscle loop. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node via the brain-muscle loop.
Constructs a LangGraph graph, feeds it the runtime request,
runs the brain-muscle loop, and returns a RuntimeResponse.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
A |
RuntimeResponse
|
and raw messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming through the brain-muscle loop.
Streams LLM output token-by-token. If tool calls are present in a complete response, the driver executes them and re-enters the loop non-streamed, then resumes streaming for the next brain call.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
|
AsyncIterator[RuntimeStreamChunk]
|
|
langchain_test
¤
Tests for the LangChain runtime driver.
Covers: - RuntimeDriver protocol compliance - execute() with FakeLLM (text responses, tool calls, brain-muscle loop) - execute() with structured output - astream() emission of RuntimeStreamChunk events - Internalized helpers (convert_to_tool_call, convert_to_tool_message, is_skill_available, is_response_structured, convert_action_to_computation, ensure_dict) - Migrated tests from brain_base_test.py and muscle_base_test.py
| CLASS | DESCRIPTION |
|---|---|
FakeLLM |
Fake LLM for driver tests. |
SimpleOutput |
|
TransferOutput |
|
TestLangChainDriverProtocol |
Tests that LangChainDriver conforms to the RuntimeDriver protocol. |
TestLangChainDriverExecute |
Tests for LangChainDriver.execute() — migrated brain_base_test. |
TestLangChainDriverMuscleLoop |
Tests for the brain-muscle loop via execute(). |
TestLangChainDriverAstream |
Tests for LangChainDriver.astream(). |
TestInternalizedHelpers |
Tests for helper methods internalized in LangChainDriver. |
TestLangChainDriverTokenUsage |
Tests for token usage in response. |
TestLangChainDriverEdgeCases |
Tests for edge case handling. |
FakeLLM
¤
Fake LLM for driver tests.
Supports:
- bind_tools (no-op passthrough)
- streaming via _astream
- sequential responses from messages iterator
| METHOD | DESCRIPTION |
|---|---|
bind_tools |
|
TransferOutput
¤
TestLangChainDriverProtocol
¤
Tests that LangChainDriver conforms to the RuntimeDriver protocol.
| METHOD | DESCRIPTION |
|---|---|
test_is_runtime_driver |
LangChainDriver should be recognized as a RuntimeDriver. |
test_has_execute_method |
LangChainDriver should have an async execute method. |
test_has_astream_method |
LangChainDriver should have an async astream method. |
test_is_runtime_driver
¤
test_is_runtime_driver()
LangChainDriver should be recognized as a RuntimeDriver.
test_has_execute_method
¤
test_has_execute_method()
LangChainDriver should have an async execute method.
test_has_astream_method
¤
test_has_astream_method()
LangChainDriver should have an async astream method.
TestLangChainDriverExecute
¤
Tests for LangChainDriver.execute() — migrated brain_base_test.
| METHOD | DESCRIPTION |
|---|---|
test_hello_text_response |
Text response from LLM → RuntimeResponse with raw_messages. |
test_returns_runtime_response_type |
execute() should always return a RuntimeResponse. |
test_execute_with_output_schema_json_match |
execute() should parse structured output when LLM returns valid JSON. |
test_skill_non_valid_raises_error |
Tool not available should raise ValueError (legacy behavior). |
test_computation_required_loop |
Brain returns tool call → muscle executes → brain returns text. |
test_execute_with_context_injection |
Context should be injected into system instructions. |
test_execute_with_multiple_messages_in_history |
Conversation history should be passed to the LLM. |
test_hello_text_response
async
¤
test_hello_text_response()
Text response from LLM → RuntimeResponse with raw_messages.
test_returns_runtime_response_type
async
¤
test_returns_runtime_response_type()
execute() should always return a RuntimeResponse.
test_execute_with_output_schema_json_match
async
¤
test_execute_with_output_schema_json_match()
execute() should parse structured output when LLM returns valid JSON.
test_skill_non_valid_raises_error
async
¤
test_skill_non_valid_raises_error()
Tool not available should raise ValueError (legacy behavior).
test_computation_required_loop
async
¤
test_computation_required_loop()
Brain returns tool call → muscle executes → brain returns text.
test_execute_with_context_injection
async
¤
test_execute_with_context_injection()
Context should be injected into system instructions.
test_execute_with_multiple_messages_in_history
async
¤
test_execute_with_multiple_messages_in_history()
Conversation history should be passed to the LLM.
TestLangChainDriverMuscleLoop
¤
Tests for the brain-muscle loop via execute().
| METHOD | DESCRIPTION |
|---|---|
test_multiple_tool_rounds |
Multiple brain-muscle rounds: request tool A → feedback → request tool B → final. |
test_direct_response_no_tools |
LLM responds directly without tool calls. |
TestLangChainDriverAstream
¤
Tests for LangChainDriver.astream().
| METHOD | DESCRIPTION |
|---|---|
test_astream_yields_chunks |
astream() should yield RuntimeStreamChunk events. |
test_astream_final_chunk |
astream() should end with a final chunk. |
test_astream_with_tool_calls |
astream() should yield tool_call and tool_result chunks. |
test_astream_multiple_tool_rounds |
astream() handles multiple tool rounds. |
test_astream_yields_chunks
async
¤
test_astream_yields_chunks()
astream() should yield RuntimeStreamChunk events.
test_astream_final_chunk
async
¤
test_astream_final_chunk()
astream() should end with a final chunk.
test_astream_with_tool_calls
async
¤
test_astream_with_tool_calls()
astream() should yield tool_call and tool_result chunks.
test_astream_multiple_tool_rounds
async
¤
test_astream_multiple_tool_rounds()
astream() handles multiple tool rounds.
TestInternalizedHelpers
¤
Tests for helper methods internalized in LangChainDriver.
| METHOD | DESCRIPTION |
|---|---|
test_convert_to_tool_call_basic |
_convert_to_tool_call should produce a valid ToolCall. |
test_convert_to_tool_call_empty_args |
_convert_to_tool_call should handle empty args. |
test_convert_to_tool_call_complex_args |
_convert_to_tool_call should handle complex nested args. |
test_convert_to_tool_message_basic |
_convert_to_tool_message should produce a valid ToolMessage. |
test_convert_to_tool_message_dict |
_convert_to_tool_message should stringify dict results. |
test_convert_to_tool_message_numeric |
_convert_to_tool_message should stringify numeric results. |
test_is_skill_available_present |
_is_skill_available should find a skill by name. |
test_is_skill_available_not_present |
_is_skill_available should return False when not found. |
test_is_skill_available_empty_list |
_is_skill_available should handle empty list. |
test_is_skill_available_case_sensitive |
_is_skill_available should be case sensitive. |
test_is_response_structured_true |
_is_response_structured should find structured skills. |
test_is_response_structured_not_structured |
_is_response_structured should return False for non-structured. |
test_is_response_structured_not_found |
_is_response_structured should return False when not found. |
test_is_response_structured_empty |
_is_response_structured should handle empty list. |
test_convert_action_to_computation_with_dict |
_convert_action_to_computation should handle ToolAgentAction. |
test_convert_action_to_computation_with_string |
_convert_action_to_computation should wrap non-dict input. |
test_convert_action_to_computation_generic_dict |
_convert_action_to_computation should handle AgentAction (no ID). |
test_convert_action_to_computation_generic_non_dict |
_convert_action_to_computation with AgentAction non-dict. |
test_ensure_dict_passes_through |
_ensure_dict should return dicts unchanged. |
test_ensure_dict_wraps_string |
_ensure_dict should wrap strings with default key. |
test_ensure_dict_wraps_string_custom_key |
_ensure_dict should use custom key when provided. |
test_ensure_dict_wraps_int |
_ensure_dict should wrap integers. |
test_ensure_dict_empty_dict |
_ensure_dict should return empty dict as-is. |
test_ensure_dict_empty_string |
_ensure_dict should wrap empty string. |
test_convert_to_tool_call_basic
¤
test_convert_to_tool_call_basic()
_convert_to_tool_call should produce a valid ToolCall.
test_convert_to_tool_call_empty_args
¤
test_convert_to_tool_call_empty_args()
_convert_to_tool_call should handle empty args.
test_convert_to_tool_call_complex_args
¤
test_convert_to_tool_call_complex_args()
_convert_to_tool_call should handle complex nested args.
test_convert_to_tool_message_basic
¤
test_convert_to_tool_message_basic()
_convert_to_tool_message should produce a valid ToolMessage.
test_convert_to_tool_message_dict
¤
test_convert_to_tool_message_dict()
_convert_to_tool_message should stringify dict results.
test_convert_to_tool_message_numeric
¤
test_convert_to_tool_message_numeric()
_convert_to_tool_message should stringify numeric results.
test_is_skill_available_present
¤
test_is_skill_available_present()
_is_skill_available should find a skill by name.
test_is_skill_available_not_present
¤
test_is_skill_available_not_present()
_is_skill_available should return False when not found.
test_is_skill_available_empty_list
¤
test_is_skill_available_empty_list()
_is_skill_available should handle empty list.
test_is_skill_available_case_sensitive
¤
test_is_skill_available_case_sensitive()
_is_skill_available should be case sensitive.
test_is_response_structured_true
¤
test_is_response_structured_true()
_is_response_structured should find structured skills.
test_is_response_structured_not_structured
¤
test_is_response_structured_not_structured()
_is_response_structured should return False for non-structured.
test_is_response_structured_not_found
¤
test_is_response_structured_not_found()
_is_response_structured should return False when not found.
test_is_response_structured_empty
¤
test_is_response_structured_empty()
_is_response_structured should handle empty list.
test_convert_action_to_computation_with_dict
¤
test_convert_action_to_computation_with_dict()
_convert_action_to_computation should handle ToolAgentAction.
test_convert_action_to_computation_with_string
¤
test_convert_action_to_computation_with_string()
_convert_action_to_computation should wrap non-dict input.
test_convert_action_to_computation_generic_dict
¤
test_convert_action_to_computation_generic_dict()
_convert_action_to_computation should handle AgentAction (no ID).
test_convert_action_to_computation_generic_non_dict
¤
test_convert_action_to_computation_generic_non_dict()
_convert_action_to_computation with AgentAction non-dict.
test_ensure_dict_passes_through
¤
test_ensure_dict_passes_through()
_ensure_dict should return dicts unchanged.
test_ensure_dict_wraps_string
¤
test_ensure_dict_wraps_string()
_ensure_dict should wrap strings with default key.
test_ensure_dict_wraps_string_custom_key
¤
test_ensure_dict_wraps_string_custom_key()
_ensure_dict should use custom key when provided.
test_ensure_dict_empty_dict
¤
test_ensure_dict_empty_dict()
_ensure_dict should return empty dict as-is.
test_ensure_dict_empty_string
¤
test_ensure_dict_empty_string()
_ensure_dict should wrap empty string.
TestLangChainDriverTokenUsage
¤
Tests for token usage in response.
| METHOD | DESCRIPTION |
|---|---|
test_execute_returns_token_usage |
execute() should return a TokenUsage in the response. |
test_execute_token_usage_zero_when_no_metadata |
Token usage should be zero when no usage_metadata. |
TestLangChainDriverEdgeCases
¤
Tests for edge case handling.
| METHOD | DESCRIPTION |
|---|---|
test_empty_tools_list |
Driver should work with empty tools list. |
test_no_conversation_history |
Driver should work without conversation history. |
test_agent_finish_with_non_string_return |
AgentFinish with non-string output should be handled. |
test_no_output_schema_fallback |
Without output_schema, should still produce a RuntimeResponse. |
test_no_conversation_history
async
¤
test_no_conversation_history()
Driver should work without conversation history.
test_agent_finish_with_non_string_return
async
¤
test_agent_finish_with_non_string_return()
AgentFinish with non-string output should be handled.
test_no_output_schema_fallback
async
¤
test_no_output_schema_fallback()
Without output_schema, should still produce a RuntimeResponse.
pydantic_ai
¤
PydanticAI runtime driver for CrewMaster v2.0.0.
Implements the RuntimeDriver protocol using PydanticAI, providing async execution and streaming against any LLM supported by PydanticAI.
| CLASS | DESCRIPTION |
|---|---|
PydanticAIDriver |
Runtime driver backed by PydanticAI. |
PydanticAIDriver
¤
PydanticAIDriver(model_name: str = 'openai:gpt-4o', default_model_settings: dict[str, Any] | None = None)
Runtime driver backed by PydanticAI.
Constructs a PydanticAI Agent from each RuntimeRequest and executes it, returning structured output through the CrewMaster Runtime SPI.
| ATTRIBUTE | DESCRIPTION |
|---|---|
model_name |
The model name (or KnownModelName) to use by default.
|
default_model_settings |
Optional default settings (temperature, etc.).
|
| PARAMETER | DESCRIPTION |
|---|---|
|
Default model to use (can be overridden per-request
via
TYPE:
|
|
Default settings like temperature, top_p, etc. |
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node using PydanticAI. |
astream |
Execute a single node with streaming output using PydanticAI. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node using PydanticAI.
Constructs an Agent from the request, runs it, and returns a RuntimeResponse with the structured output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
RuntimeResponse with structured output, token usage, and messages. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming output using PydanticAI.
Yields RuntimeStreamChunk events (text_delta, tool_call, tool_result, final) as the agent produces output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
RuntimeStreamChunk events during agent execution. |
pydantic_ai_test
¤
Tests for the PydanticAI runtime driver.
Covers: - Driver construction with default model - execute() against a mock (no real LLM call) - execute() against a real model (integration test) - astream() emission of chunks - RuntimeDriver protocol compliance
| CLASS | DESCRIPTION |
|---|---|
TestPydanticAIDriverProtocol |
Tests that PydanticAIDriver conforms to RuntimeDriver protocol. |
TestPydanticAIDriverConstruction |
Tests for driver initialization. |
TestPydanticAIDriverExecute |
Tests for the execute() method. |
TestPydanticAIDriverAstream |
Tests for the astream() method. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
needs_openai |
|
pytestmark |
|
needs_openai
module-attribute
¤
needs_openai = skipif(not get('OPENAI_API_KEY'), reason='OPENAI_API_KEY not set — skipping integration test that needs a real LLM')
pytestmark
module-attribute
¤
pytestmark = skipif(PydanticAIDriver is None, reason='pydantic_ai not installed — skipping all PydanticAIDriver tests')
TestPydanticAIDriverProtocol
¤
Tests that PydanticAIDriver conforms to RuntimeDriver protocol.
| METHOD | DESCRIPTION |
|---|---|
test_is_runtime_driver |
PydanticAIDriver should be recognized as a RuntimeDriver. |
test_has_execute_method |
PydanticAIDriver should have an execute method. |
test_has_astream_method |
PydanticAIDriver should have an astream method. |
test_is_runtime_driver
¤
test_is_runtime_driver()
PydanticAIDriver should be recognized as a RuntimeDriver.
TestPydanticAIDriverConstruction
¤
Tests for driver initialization.
| METHOD | DESCRIPTION |
|---|---|
test_default_model_name |
PydanticAIDriver should default to gpt-4o. |
test_custom_model_name |
PydanticAIDriver should accept a custom model name. |
test_default_model_settings |
PydanticAIDriver should accept default model settings. |
test_no_default_settings_by_default |
PydanticAIDriver should have empty default settings. |
test_custom_model_name
¤
test_custom_model_name()
PydanticAIDriver should accept a custom model name.
test_default_model_settings
¤
test_default_model_settings()
PydanticAIDriver should accept default model settings.
test_no_default_settings_by_default
¤
test_no_default_settings_by_default()
PydanticAIDriver should have empty default settings.
TestPydanticAIDriverExecute
¤
Tests for the execute() method.
| METHOD | DESCRIPTION |
|---|---|
test_execute_returns_runtime_response |
execute() should return a RuntimeResponse. |
test_execute_with_simple_prompt |
execute() should process a simple prompt and return output. |
test_execute_returns_token_usage |
execute() should return token usage information. |
test_execute_with_context |
execute() should incorporate context into instructions. |
test_execute_with_model_override |
execute() should use model from runtime_hints. |
test_execute_without_output_schema |
execute() should work without an output schema (plain text). |
test_execute_returns_runtime_response
async
¤
test_execute_returns_runtime_response()
execute() should return a RuntimeResponse.
test_execute_with_simple_prompt
async
¤
test_execute_with_simple_prompt()
execute() should process a simple prompt and return output.
test_execute_returns_token_usage
async
¤
test_execute_returns_token_usage()
execute() should return token usage information.
test_execute_with_context
async
¤
test_execute_with_context()
execute() should incorporate context into instructions.
test_execute_with_model_override
async
¤
test_execute_with_model_override()
execute() should use model from runtime_hints.
test_execute_without_output_schema
async
¤
test_execute_without_output_schema()
execute() should work without an output schema (plain text).
TestPydanticAIDriverAstream
¤
Tests for the astream() method.
| METHOD | DESCRIPTION |
|---|---|
test_astream_yields_chunks |
astream() should yield RuntimeStreamChunk events. |
test_astream_returns_final_chunk |
astream() should end with a final chunk. |
test_astream_without_output_schema |
astream() should work without an output schema. |
test_astream_yields_chunks
async
¤
test_astream_yields_chunks()
astream() should yield RuntimeStreamChunk events.
test_astream_returns_final_chunk
async
¤
test_astream_returns_final_chunk()
astream() should end with a final chunk.
test_astream_without_output_schema
async
¤
test_astream_without_output_schema()
astream() should work without an output schema.
retry
¤
Secure retry execution for CrewMaster v2.0.0.
Provides secure_retry_execution — a retry wrapper that wraps a driver
call, validates the output against the expected schema, and retries with
error feedback injected into the next attempt.
| FUNCTION | DESCRIPTION |
|---|---|
secure_retry_execution |
Execute an async driver call with validation retries. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
RetryFunc |
|
secure_retry_execution
async
¤
secure_retry_execution(func: RetryFunc, max_attempts: int = 5, delay_seconds: float = 1.0, output_schema: type[BaseModel] | None = None) -> RuntimeResponse
Execute an async driver call with validation retries.
If output_schema is provided, the function validates that the
runtime response output conforms to the schema. On validation failure,
the error detail is recorded and an exception is raised so the caller
(typically the plan executor) can retry with error feedback injected
into the next request's instructions.
| PARAMETER | DESCRIPTION |
|---|---|
|
Async callable that returns a RuntimeResponse (driver call).
TYPE:
|
|
Maximum number of attempts before giving up.
TYPE:
|
|
Delay (in seconds) between retry attempts.
TYPE:
|
|
Optional Pydantic model to validate the output against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
The RuntimeResponse from a successful attempt. |
| RAISES | DESCRIPTION |
|---|---|
RetryExhaustedError
|
If all attempts are exhausted. |
ValidationError
|
If output_schema validation fails on the last attempt and the error is not wrapped. |
retry_test
¤
Tests for secure_retry_execution.
Covers: - Successful execution on first attempt - Retry after transient failures - Exhaustion of all attempts - Output schema validation retries - Validation error feedback
| CLASS | DESCRIPTION |
|---|---|
MockOutput |
|
TestSecureRetryExecution |
Tests for the secure_retry_execution wrapper. |
TestSecureRetryExecution
¤
Tests for the secure_retry_execution wrapper.
| METHOD | DESCRIPTION |
|---|---|
test_succeeds_on_first_attempt |
Should return result on first successful attempt. |
test_retries_on_exception |
Should retry after an exception and succeed. |
test_exhausts_all_attempts |
Should raise after exhausting all attempts. |
test_retries_on_schema_mismatch |
Should retry when output type doesn't match schema. |
test_raises_validation_error_on_exhaustion |
Should raise ValidationError if output schema never matches. |
test_skips_validation_when_schema_is_none |
Should not validate output when no schema is provided. |
test_skips_validation_when_output_is_none |
Should not validate when response output is None. |
test_uses_custom_max_attempts |
Should respect custom max_attempts. |
test_uses_custom_delay |
Should respect custom delay between retries. |
test_default_parameters |
Should work with default max_attempts and delay. |
test_succeeds_on_first_attempt
async
¤
test_succeeds_on_first_attempt()
Should return result on first successful attempt.
test_retries_on_exception
async
¤
test_retries_on_exception()
Should retry after an exception and succeed.
test_exhausts_all_attempts
async
¤
test_exhausts_all_attempts()
Should raise after exhausting all attempts.
test_retries_on_schema_mismatch
async
¤
test_retries_on_schema_mismatch()
Should retry when output type doesn't match schema.
test_raises_validation_error_on_exhaustion
async
¤
test_raises_validation_error_on_exhaustion()
Should raise ValidationError if output schema never matches.
test_skips_validation_when_schema_is_none
async
¤
test_skips_validation_when_schema_is_none()
Should not validate output when no schema is provided.
test_skips_validation_when_output_is_none
async
¤
test_skips_validation_when_output_is_none()
Should not validate when response output is None.
test_uses_custom_max_attempts
async
¤
test_uses_custom_max_attempts()
Should respect custom max_attempts.
test_uses_custom_delay
async
¤
test_uses_custom_delay()
Should respect custom delay between retries.
test_default_parameters
async
¤
test_default_parameters()
Should work with default max_attempts and delay.
runtime
¤
Runtime SPI models for CrewMaster v2.0.0.
The Runtime SPI defines the contract between CrewMaster's execution layer and concrete LLM runtimes (PydanticAI, LangChain, etc.). Every driver must implement the RuntimeDriver protocol.
Key types:
- RuntimeRequest: The instruction, tools, and context sent to a runtime.
- RuntimeResponse: The structured output, token usage, and raw messages returned by a runtime.
- RuntimeStreamChunk: A discriminated union of streaming event types.
- RuntimeDriver: The async protocol that all runtime drivers must implement.
- TokenUsage: Token accounting for a single runtime invocation.
| CLASS | DESCRIPTION |
|---|---|
TokenUsage |
Token usage for a single runtime invocation. |
RuntimeRequest |
A request to execute an operation node against a runtime driver. |
RuntimeResponse |
The response from a runtime driver after executing a node. |
RuntimeStreamChunk |
A streaming event emitted during multi-node execution. |
RuntimeDriver |
Protocol for runtime drivers that execute operations against LLMs. |
TokenUsage
¤
Token usage for a single runtime invocation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
input_tokens |
Number of tokens consumed by the input (prompt).
TYPE:
|
output_tokens |
Number of tokens generated by the output.
TYPE:
|
RuntimeRequest
¤
A request to execute an operation node against a runtime driver.
| ATTRIBUTE | DESCRIPTION |
|---|---|
instructions |
The fully assembled and rendered prompt text.
TYPE:
|
tools |
The list of tool schemas visible to this node. |
context |
Resolved context dictionary for template variables. |
output_schema |
The Pydantic model type that the output must conform to.
TYPE:
|
runtime_hints |
Arbitrary driver-specific hints (model name, temp, etc.). |
conversation_history |
Previous messages for multi-turn execution. |
RuntimeResponse
¤
The response from a runtime driver after executing a node.
| ATTRIBUTE | DESCRIPTION |
|---|---|
output |
The structured output parsed into the requested schema (or None).
TYPE:
|
token_usage |
Token accounting for this invocation.
TYPE:
|
raw_messages |
The raw message list from the LLM provider. |
state |
Arbitrary driver state that may be needed downstream. |
token_usage
class-attribute
instance-attribute
¤
token_usage: TokenUsage = Field(default_factory=TokenUsage)
raw_messages
class-attribute
instance-attribute
¤
RuntimeStreamChunk
¤
A streaming event emitted during multi-node execution.
This is a discriminated union keyed on kind. Each kind carries
a different set of populated fields.
| ATTRIBUTE | DESCRIPTION |
|---|---|
kind |
The event type.
TYPE:
|
content |
Text delta content (for
TYPE:
|
tool_name |
Name of the tool being called (for
TYPE:
|
tool_args |
Arguments for the tool call (for |
tool_output |
Output from a tool execution (for
TYPE:
|
output |
The final parsed output model (for
TYPE:
|
node_name |
The name of the completed node (for
TYPE:
|
artifact |
The intermediate artifact from the node (for
TYPE:
|
RuntimeDriver
¤
Protocol for runtime drivers that execute operations against LLMs.
Every runtime driver (PydanticAI, LangChain, etc.) must implement this
protocol. CrewMaster injects drivers per-agent via AgentConfig.runtime,
with a fallback to the default_runtime passed to execute().
Usage::
class PydanticAIDriver:
async def execute(self, request: RuntimeRequest) -> RuntimeResponse:
...
async def astream(
self, request: RuntimeRequest
) -> AsyncIterator[RuntimeStreamChunk]:
...
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a single node synchronously (from the caller's perspective). |
astream |
Execute a single node with streaming output. |
execute
async
¤
execute(request: RuntimeRequest) -> RuntimeResponse
Execute a single node synchronously (from the caller's perspective).
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RuntimeResponse
|
A RuntimeResponse with the structured output. |
astream
async
¤
astream(request: RuntimeRequest) -> AsyncIterator[RuntimeStreamChunk]
Execute a single node with streaming output.
| PARAMETER | DESCRIPTION |
|---|---|
|
The fully assembled runtime request.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[RuntimeStreamChunk]
|
RuntimeStreamChunk events as the LLM produces output. |
runtime_test
¤
Tests for Runtime SPI models.
| CLASS | DESCRIPTION |
|---|---|
TestTokenUsage |
|
TestRuntimeRequest |
|
TestRuntimeResponse |
|
TestRuntimeStreamChunk |
|
TestRuntimeDriverProtocol |
|
TestTokenUsage
¤
| METHOD | DESCRIPTION |
|---|---|
test_defaults |
TokenUsage should default to zero tokens. |
test_full_construction |
TokenUsage should accept token counts. |
test_serialization_roundtrip |
TokenUsage should serialize and deserialize. |
TestRuntimeRequest
¤
| METHOD | DESCRIPTION |
|---|---|
test_defaults |
RuntimeRequest should have sensible defaults for optional fields. |
test_full_construction |
RuntimeRequest should accept all fields. |
test_instructions_required |
RuntimeRequest should require instructions. |
test_accepts_arbitrary_output_schema_type |
RuntimeRequest should accept Pydantic model types. |
TestRuntimeResponse
¤
| METHOD | DESCRIPTION |
|---|---|
test_defaults |
RuntimeResponse should have sensible defaults. |
test_full_construction |
RuntimeResponse should accept all fields. |
test_output_accepts_none |
RuntimeResponse.output should accept None. |
test_accepts_pydantic_output |
RuntimeResponse should accept Pydantic model instances. |
test_serialization_roundtrip |
RuntimeResponse should serialize and deserialize. |
TestRuntimeStreamChunk
¤
| METHOD | DESCRIPTION |
|---|---|
test_text_delta_kind |
RuntimeStreamChunk with kind='text_delta' should carry content. |
test_tool_call_kind |
RuntimeStreamChunk with kind='tool_call' should carry tool info. |
test_tool_result_kind |
RuntimeStreamChunk with kind='tool_result' should carry tool output. |
test_node_complete_kind |
RuntimeStreamChunk with kind='node_complete' should carry node info. |
test_final_kind |
RuntimeStreamChunk with kind='final' should carry output. |
test_invalid_kind_rejected |
RuntimeStreamChunk should reject invalid kinds. |
test_defaults_on_other_fields |
RuntimeStreamChunk should default unused fields to None. |
test_serialization_roundtrip |
RuntimeStreamChunk should serialize and deserialize. |
test_text_delta_kind
¤
test_text_delta_kind()
RuntimeStreamChunk with kind='text_delta' should carry content.
test_tool_call_kind
¤
test_tool_call_kind()
RuntimeStreamChunk with kind='tool_call' should carry tool info.
test_tool_result_kind
¤
test_tool_result_kind()
RuntimeStreamChunk with kind='tool_result' should carry tool output.
test_node_complete_kind
¤
test_node_complete_kind()
RuntimeStreamChunk with kind='node_complete' should carry node info.
test_invalid_kind_rejected
¤
test_invalid_kind_rejected()
RuntimeStreamChunk should reject invalid kinds.
test_defaults_on_other_fields
¤
test_defaults_on_other_fields()
RuntimeStreamChunk should default unused fields to None.
test_serialization_roundtrip
¤
test_serialization_roundtrip()
RuntimeStreamChunk should serialize and deserialize.
TestRuntimeDriverProtocol
¤
| METHOD | DESCRIPTION |
|---|---|
test_is_runtime_checkable |
RuntimeDriver should be a runtime-checkable protocol. |
test_conforming_class_passes_isinstance |
A class implementing execute() and astream() should be recognized. |
test_non_conforming_class_fails_isinstance |
A class without execute/astream should not be recognized. |
test_missing_astream_fails |
A class with execute but no astream should not be recognized. |
test_missing_execute_fails |
A class with astream but no execute should not be recognized. |
test_is_runtime_checkable
¤
test_is_runtime_checkable()
RuntimeDriver should be a runtime-checkable protocol.
test_conforming_class_passes_isinstance
¤
test_conforming_class_passes_isinstance()
A class implementing execute() and astream() should be recognized.
test_non_conforming_class_fails_isinstance
¤
test_non_conforming_class_fails_isinstance()
A class without execute/astream should not be recognized.
test_missing_astream_fails
¤
test_missing_astream_fails()
A class with execute but no astream should not be recognized.
test_missing_execute_fails
¤
test_missing_execute_fails()
A class with astream but no execute should not be recognized.