Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIPexStudio AIPex AIPex runExecution

From Leeroopedia
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

Uses Heuristics

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment