Function Execution¶
Function execution utilities for LLM tool calling - Version 2.
Provides structured function orchestration with clear input/output contracts and resilient error handling for the Arshai agentic framework.
Classes¶
- class arshai.llms.utils.function_execution.FunctionCall(name, args, call_id=None, is_background=False)[source]¶
Bases:
objectRepresents a single function call with metadata.
- __init__(name, args, call_id=None, is_background=False)¶
- class arshai.llms.utils.function_execution.FunctionExecutionInput(function_calls, available_functions, available_background_tasks)[source]¶
Bases:
objectStructured input for function execution orchestrator.
-
function_calls:
List[FunctionCall]¶
- __init__(function_calls, available_functions, available_background_tasks)¶
-
function_calls:
- class arshai.llms.utils.function_execution.FunctionExecutionResult(regular_results, background_initiated, failed_functions)[source]¶
Bases:
objectStructured result from function execution orchestrator.
- __init__(regular_results, background_initiated, failed_functions)¶
- class arshai.llms.utils.function_execution.FunctionOrchestrator[source]¶
Bases:
objectSimplified function execution orchestrator for LLM tool calling.
Handles parallel execution of regular functions and background tasks with resilient error handling and structured input/output.
Supports both batch execution (original) and progressive execution (new) for real-time streaming scenarios.
- async execute_functions(execution_input)[source]¶
Execute function calls based on structured input and return structured results.
- Parameters:
execution_input (
FunctionExecutionInput) – Structured input containing function calls and available functions- Return type:
- Returns:
FunctionExecutionResult with results, background task status, and any errors
- async execute_function_progressively(function_call, available_functions, available_background_tasks)[source]¶
Execute a single function immediately and return the task.
This enables real-time progressive execution during streaming, where functions execute as soon as they’re complete rather than waiting for the entire stream to finish.
- Parameters:
- Return type:
Task- Returns:
asyncio.Task that can be awaited later for the result
- async gather_progressive_results(function_tasks)[source]¶
Gather results from progressively executed functions.
This method waits for all progressive tasks to complete and consolidates their results into a structured format.
- Parameters:
function_tasks (
List[Task]) – List of tasks from progressive execution- Return type:
- Returns:
FunctionExecutionResult with consolidated results
- class arshai.llms.utils.function_execution.StreamingExecutionState(active_function_tasks=None, executed_functions=None, completed_functions=None, background_initiated=None)[source]¶
Bases:
objectTracks progressive execution state during streaming.
This class maintains the state of function executions that happen progressively during streaming, preventing duplicate executions and tracking active tasks.
- __init__(active_function_tasks=None, executed_functions=None, completed_functions=None, background_initiated=None)¶