Implementation:AIPexStudio AIPex AIPex runExecution
| Knowledge Sources | |
|---|---|
| Domains | AI_Agent, Core |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete internal execution generator that drives the OpenAI Agents SDK run loop, shapes screenshot items, streams content/tool events, collects metrics, and persists the session.
Description
The runExecution method is the core of the agent loop. It calls the OpenAI Agents SDK's `run()` function with streaming enabled, passing a `callModelInputFilter` that invokes `shapeScreenshotItems` to strip base64 from tool results and inject transient vision messages before each model call. It iterates the SDK's stream, detecting tool-call argument streaming from raw provider events, emitting normalized `AgentEvent`s for content deltas and tool calls, collecting usage metrics from the final response, persisting the session, and running `afterResponse` plugin hooks. On error, it normalizes the error, emits metrics, and yields an error event.
Usage
This method is called internally by `chat()`. It is not invoked directly by consumers. It is documented here as the implementation of the streaming execution and metrics/persistence principles.
Code Reference
Source Location
- Repository: AIPex
- File: packages/core/src/agent/aipex.ts
- Lines: L119-342
Signature
private async *runExecution(
input: string | AgentInputItem[],
session: Session | null
): AsyncGenerator<AgentEvent>
Import
// Internal method — not exported. Called by AIPex.chat().
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input | AgentInputItem[] | Yes | Final input (text or multimodal items) |
| session | null | Yes | Conversation session (null for stateless) |
Outputs
| Name | Type | Description |
|---|---|---|
| yields | AgentEvent | content_delta, tool_call_args_streaming_start/complete, tool_call_start/complete/error, metrics_update, execution_complete, error |
Usage Examples
Internal Flow (Illustrative)
// Called internally by chat():
// const session = await conversationManager.createSession();
// yield* this.runExecution(finalInput, session);
// The method internally:
// 1. Calls run(agent, input, { stream: true, callModelInputFilter: shapeScreenshotItems })
// 2. Iterates SDK stream events
// 3. Emits normalized AgentEvents
// 4. Collects metrics from result.rawResponses
// 5. Saves session via ConversationManager
// 6. Runs afterResponse plugin hooks
Related Pages
Implements Principle
- Principle:AIPexStudio_AIPex_Agent_Execution_Lifecycle
- Principle:AIPexStudio_AIPex_Streaming_Event_Architecture
- Principle:AIPexStudio_AIPex_Metrics_And_Persistence