Overview
Concrete factory method for creating an AIPex agent instance with model, tools, conversation management, and plugins, provided by the @aipexstudio/aipex-core package.
Description
The AIPex.create static method is the entry point for the AIPex agent framework. It wraps the OpenAI Agents SDK's `Agent` class, adding conversation session management, context resolution, plugin hooks, and screenshot shaping. It constructs an `OpenAIAgent` with the provided model, instructions, and tools, then builds a `ConversationManager` (unless conversation is disabled) with optional compression and custom storage. The returned `AIPex` instance is the primary object for all subsequent chat interactions.
Usage
- Standard agent: provide `model`, `instructions`, and `tools` for a fully-featured agent with session persistence.
- Stateless mode: set `conversation: false` for ephemeral, single-turn interactions (no session saved).
- With compression: provide `compression.model` and `compression.summarizeAfterItems` to enable automatic conversation summarization for long sessions.
- With plugins: pass an array of `AgentPlugin` objects to hook into `beforeChat`, `afterResponse`, `onToolEvent`, and `onMetrics` lifecycle events.
Code Reference
Source Location
- Repository: AIPex
- File: packages/core/src/agent/aipex.ts
- Lines: L57-102
Signature
static create(options: AIPexOptions): AIPex
interface AIPexOptions<TTools extends readonly FunctionTool[] = FunctionTool[]> {
name?: string;
instructions: string;
model: AiSdkModel;
tools?: TTools;
maxTurns?: number;
conversation?: false;
storage?: SessionStorageAdapter;
compression?: CompressionOptions;
conversationManager?: ConversationManager;
contextManager?: ContextManager;
plugins?: AgentPlugin[];
}
Import
import { AIPex } from "@aipexstudio/aipex-core";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| options.instructions |
string |
Yes |
System prompt for the agent
|
| options.model |
AiSdkModel |
Yes |
AI model (create via aisdk() with a provider)
|
| options.name |
string |
No |
Agent name (default "Assistant")
|
| options.tools |
FunctionTool[] |
No |
Tools available to the agent (default [])
|
| options.maxTurns |
number |
No |
Max agent loop turns (default 2000)
|
| options.conversation |
false |
No |
Disable conversation management (stateless)
|
| options.storage |
SessionStorageAdapter |
No |
Custom session storage (default InMemoryStorage)
|
| options.compression |
CompressionOptions |
No |
Conversation compression config
|
| options.contextManager |
ContextManager |
No |
Context provider orchestrator
|
| options.plugins |
AgentPlugin[] |
No |
Lifecycle hook plugins
|
Outputs
| Name |
Type |
Description
|
| returns |
AIPex |
Agent instance ready for chat() calls
|
Usage Examples
Basic Agent
import { AIPex } from "@aipexstudio/aipex-core";
import { openai } from "@ai-sdk/openai";
import { aisdk } from "@openai/agents-extensions";
const agent = AIPex.create({
instructions: "You are a helpful browser automation assistant.",
model: aisdk(openai("gpt-4o")),
tools: myTools,
});
for await (const event of agent.chat("Click the login button")) {
console.log(event.type, event);
}
Stateless Agent with Plugins
const agent = AIPex.create({
instructions: "You are a coding assistant.",
model: aisdk(anthropic("claude-sonnet-4-20250514")),
conversation: false,
plugins: [
{
id: "logger",
hooks: {
afterResponse: async (payload) => {
console.log("Turn complete:", payload.metrics.tokensUsed, "tokens");
},
},
},
],
});
Related Pages
Implements Principle
Uses Heuristics
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.