Skip to main content

Installation

npm install agi

Quick Example

30 seconds to your first agent. Here’s everything you need:
import { AGIClient } from 'agi';

const client = new AGIClient({ apiKey: 'your_api_key' });

// Create session and run task
const session = await client.createSession('agi-0');
try {
    const result = await session.runTask('Find three nonstop SFO→JFK flights next month under $450');
    console.log(result);
} finally {
    await session.delete();
}

Step-by-Step Guide

Follow these steps to deploy your first production-ready agent.
1

Get your API key

Get Access

Sign up for the AGI Platform to get your API key
Store it securely as it provides access to create and manage agent sessions.
2

Create a session

Start by creating a new agent session. The packages handle this automatically:
import { AGIClient } from 'agi';

const client = new AGIClient({ apiKey: 'your_api_key' });
const session = await client.createSession('agi-0');

// Get VNC URL to watch agent work
console.log(session.vncUrl);
Open the vnc_url in a browser to watch the agent work in real-time!
3

Send a task message

Give the agent a task. The packages handle polling automatically:
const result = await session.runTask('Search for the top 3 articles about AI agents and summarize them');
4

Monitor progress

The packages automatically poll for results. For real-time updates, use event streaming:
// Automatic polling (default)
const result = await session.runTask('Your task');

// Real-time streaming
for await (const event of session.streamEvents()) {
    console.log(event);
}
5

Respond to questions

If the agent asks a question, respond using the same method:
const result = await session.runTask('Yes, evening flights are preferred');
6

Clean up

The packages handle cleanup automatically. With context managers (Python) or try/finally (JavaScript):
// Manual cleanup
const session = await client.createSession('agi-0');
try {
    const result = await session.runTask('Your task');
} finally {
    await session.delete();
}

Complete Examples

Here are complete examples using the official packages:
import { AGIClient } from 'agi';

const client = new AGIClient({ apiKey: 'your_api_key' });

// Simple usage with manual cleanup
const session = await client.createSession('agi-0');
try {
    const result = await session.runTask('Find three nonstop SFO→JFK options next month under $450');
    console.log(result);
} finally {
    await session.delete();
}

Additional Operations

Control Execution

Pause, resume, or cancel a running task:
// Pause
await session.pause();

// Resume
await session.resume();

// Cancel
await session.cancel();
Manually navigate the browser to a specific URL:
await session.navigate('https://www.example.com');

Take Screenshot

Get a base64-encoded screenshot of the current browser state:
const screenshot = await session.screenshot();

Next Steps

You’re ready to build. Explore these resources to take your agents to the next level:
Need help? Our team is here to support you. Reach out at [email protected] or visit theagi.company.