praval.model_runtime
Provider-neutral model runtime.
The runtime is the stable execution boundary between agents and providers. It keeps the legacy string API working while exposing neutral request/response objects for newer provider features.
Functions
|
Execute a legacy provider tool call with optional HITL gating. |
|
Execute a tool on the caller's event loop with optional HITL gating. |
|
Convert a legacy Praval tool dict to a neutral ToolSpec. |
|
Normalize public multimodal content input to ContentPart instances. |
|
Normalize public reasoning config values. |
Normalize public structured-output config values. |
Classes
|
Runtime wrapper for provider-neutral model execution. |
- praval.model_runtime.normalize_structured_output_config(value)[source]
Normalize public structured-output config values.
- Return type:
Optional[StructuredOutputConfig]- Parameters:
value (Any)
- praval.model_runtime.normalize_reasoning_config(value)[source]
Normalize public reasoning config values.
- Return type:
Optional[ReasoningConfig]- Parameters:
value (Any)
- praval.model_runtime.normalize_content_parts(value)[source]
Normalize public multimodal content input to ContentPart instances.
- Return type:
Any- Parameters:
value (Any)
- praval.model_runtime.legacy_tool_to_spec(tool, *, strict=False)[source]
Convert a legacy Praval tool dict to a neutral ToolSpec.
- Return type:
Optional[ToolSpec]- Parameters:
tool (Dict[str, Any])
strict (bool)
- praval.model_runtime.execute_legacy_tool_call(*, hitl_context, tool_call_id, function_name, raw_args, available_tools, continuation_state=None, resume_intervention=None)[source]
Execute a legacy provider tool call with optional HITL gating.
- Return type:
str- Parameters:
hitl_context (Dict[str, Any] | None)
tool_call_id (str)
function_name (str)
raw_args (Any)
available_tools (List[Dict[str, Any]])
continuation_state (Dict[str, Any] | None)
resume_intervention (Dict[str, Any] | None)
- async praval.model_runtime.execute_legacy_tool_call_async(*, hitl_context, tool_call_id, function_name, raw_args, available_tools, continuation_state=None, resume_intervention=None)[source]
Execute a tool on the caller’s event loop with optional HITL gating.
- Return type:
Any- Parameters:
hitl_context (Dict[str, Any] | None)
tool_call_id (str)
function_name (str)
raw_args (Any)
available_tools (List[Dict[str, Any]])
continuation_state (Dict[str, Any] | None)
resume_intervention (Dict[str, Any] | None)
- class praval.model_runtime.ModelRuntime(*, provider, provider_name, config)[source]
Bases:
objectRuntime wrapper for provider-neutral model execution.
- Parameters:
provider (Any)
provider_name (str)
config (Any)
- __init__(*, provider, provider_name, config)[source]
- Parameters:
provider (Any)
provider_name (str)
config (Any)
- Return type:
None
- property capabilities: ProviderCapabilities
Return provider capabilities if exposed.
- invoke(*, messages, tools=None, hitl_context=None, response_schema=None, reasoning=None, provider_options=None, timeout=None, metadata=None, stream_options=None, stream=False)[source]
Execute a model request and return a neutral response.
- Return type:
- Parameters:
messages (List[Dict[str, Any]])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)
response_schema (StructuredOutputConfig | None)
reasoning (ReasoningConfig | None)
provider_options (Dict[str, Any] | None)
timeout (float | None)
metadata (Dict[str, Any] | None)
stream_options (Dict[str, Any] | None)
stream (bool)
- generate_text(*, messages, tools=None, hitl_context=None, **kwargs)[source]
Execute a request and return text for legacy callers.
- Return type:
str- Parameters:
messages (List[Dict[str, Any]])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)
kwargs (Any)
- async ainvoke(*, messages, tools=None, hitl_context=None, response_schema=None, reasoning=None, provider_options=None, timeout=None, metadata=None, stream_options=None)[source]
Execute providers and tools without moving async tools across loops.
- Return type:
- Parameters:
messages (List[Dict[str, Any]])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)
response_schema (StructuredOutputConfig | None)
reasoning (ReasoningConfig | None)
provider_options (Dict[str, Any] | None)
timeout (float | None)
metadata (Dict[str, Any] | None)
stream_options (Dict[str, Any] | None)
- stream(*, messages, tools=None, hitl_context=None, response_schema=None, reasoning=None, provider_options=None, timeout=None, metadata=None, stream_options=None)[source]
Stream normalized model events.
- Return type:
Iterator[ModelEvent]- Parameters:
messages (List[Dict[str, Any]])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)
response_schema (StructuredOutputConfig | None)
reasoning (ReasoningConfig | None)
provider_options (Dict[str, Any] | None)
timeout (float | None)
metadata (Dict[str, Any] | None)
stream_options (Dict[str, Any] | None)
- async astream(*, messages, tools=None, hitl_context=None, response_schema=None, reasoning=None, provider_options=None, timeout=None, metadata=None, stream_options=None)[source]
Asynchronously stream normalized model events.
- Return type:
AsyncIterator[ModelEvent]- Parameters:
messages (List[Dict[str, Any]])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)
response_schema (StructuredOutputConfig | None)
reasoning (ReasoningConfig | None)
provider_options (Dict[str, Any] | None)
timeout (float | None)
metadata (Dict[str, Any] | None)
stream_options (Dict[str, Any] | None)
- resolve_capabilities(request)[source]
Resolve effective capabilities for a request.
- Return type:
- Parameters:
request (ModelRequest)
- validate_request(request)[source]
Validate a model request before provider execution.
- Return type:
None- Parameters:
request (ModelRequest)
- resume_tool_flow(suspended_state, tools, hitl_context=None)[source]
Resume a runtime-owned tool loop after a HITL decision.
- Return type:
- Parameters:
suspended_state (Dict[str, Any])
tools (List[Dict[str, Any]] | None)
hitl_context (Dict[str, Any] | None)