Skip to main content

Official API of OpenAGI Foundation

Project description

OAGI Python SDK

Python SDK for the OAGI API - vision-based task automation.

Installation

# Recommended: All features (desktop automation + server)
pip install oagi

# Or install core only (minimal dependencies)
pip install oagi-core

# Or install with specific features
pip install oagi-core[desktop]  # Desktop automation support
pip install oagi-core[server]   # Server support

Requires Python >= 3.10

Installation Options

  • oagi (Recommended): Metapackage that includes all features (desktop + server). Equivalent to oagi-core[desktop,server].
  • oagi-core: Core SDK with minimal dependencies (httpx, pydantic). Suitable for server deployments or custom automation setups.
  • oagi-core[desktop]: Adds pyautogui and pillow for desktop automation features like screenshot capture and GUI control.
  • oagi-core[server]: Adds FastAPI and Socket.IO dependencies for running the real-time server for browser extensions.

Note: Features requiring desktop dependencies (like PILImage.from_screenshot(), PyautoguiActionHandler, ScreenshotMaker) will show helpful error messages if you try to use them without installing the desktop extra.

Quick Start

Set your API credentials:

export OAGI_API_KEY="your-api-key" # get your API key from https://developer.openagi.org/
# export OAGI_BASE_URL="https://api.agiopen.org/", # optional, defaults to production endpoint

Automated Task Execution

Run tasks automatically with screenshot capture and action execution:

import asyncio
from oagi import AsyncDefaultAgent, AsyncPyautoguiActionHandler, AsyncScreenshotMaker

async def main():
    agent = AsyncDefaultAgent(max_steps=10)
    completed = await agent.execute(
        "Search weather on Google",
        action_handler=AsyncPyautoguiActionHandler(),  # Executes mouse/keyboard actions
        image_provider=AsyncScreenshotMaker(),         # Captures screenshots
    )
    return completed

asyncio.run(main())

Configure PyAutoGUI behavior with custom settings:

from oagi import AsyncPyautoguiActionHandler, PyautoguiConfig

# Customize action behavior
config = PyautoguiConfig(
    drag_duration=1.0,      # Slower drags for precision (default: 0.5)
    scroll_amount=50,       # Larger scroll steps (default: 30)
    wait_duration=2.0,      # Longer waits (default: 1.0)
    action_pause=0.2,       # More pause between actions (default: 0.1)
    hotkey_interval=0.1,    # Interval between keys in hotkey combinations (default: 0.1)
    capslock_mode="session" # Caps lock mode: 'session' or 'system' (default: 'session')
)

action_handler = AsyncPyautoguiActionHandler(config=config)

Image Processing

Process and optimize images before sending to API:

from oagi import PILImage, ImageConfig

# Load and compress an image
image = PILImage.from_file("large_screenshot.png")
config = ImageConfig(
    format="JPEG",
    quality=85,
    width=1260,
    height=700
)
compressed = image.transform(config)

Manual Control with Actor

For step-by-step control over task execution:

import asyncio
from oagi import AsyncActor, AsyncPyautoguiActionHandler, AsyncScreenshotMaker

async def main():
    async with AsyncActor() as actor:
        await actor.init_task("Complete the form")
        image_provider = AsyncScreenshotMaker()
        action_handler = AsyncPyautoguiActionHandler()

        for _ in range(10):
            image = await image_provider()
            step = await actor.step(image)

            if step.stop:
                break

            await action_handler(step.actions)

asyncio.run(main())

Examples

See the examples/ directory for more usage patterns:

  • execute_task_auto.py - Automated task execution with AsyncDefaultAgent
  • execute_task_manual.py - Manual step-by-step control with Actor
  • continued_session.py - Continuing tasks across sessions
  • screenshot_with_config.py - Image compression and optimization
  • socketio_server_basic.py - Socket.IO server example
  • socketio_client_example.py - Socket.IO client implementation

Socket.IO Server (Optional)

The SDK includes an optional Socket.IO server for real-time bidirectional communication with browser extensions or custom clients.

Installation

# Install with server support
pip install oagi  # Includes server features
# Or
pip install oagi-core[server]  # Core + server only

Running the Server

import uvicorn
from oagi.server import create_app, ServerConfig

# Create FastAPI app with Socket.IO
app = create_app()

# Run server
uvicorn.run(app, host="0.0.0.0", port=8000)

Or use the example script:

export OAGI_API_KEY="your-api-key"
python examples/socketio_server_basic.py

Server Features

  • Dynamic namespaces: Each session gets its own namespace (/session/{session_id})
  • Simplified events: Single init event from client with instruction
  • Action execution: Emit individual actions (click, type, scroll, etc.) to client
  • S3 integration: Server sends presigned URLs for direct screenshot uploads
  • Session management: In-memory session storage with timeout cleanup
  • REST API: Health checks and session management endpoints

Client Integration

Clients connect to a session namespace and handle action events:

import socketio

sio = socketio.AsyncClient()
namespace = "/session/my_session_id"

@sio.on("request_screenshot", namespace=namespace)
async def on_screenshot(data):
    # Upload screenshot to S3 using presigned URL
    return {"success": True}

@sio.on("click", namespace=namespace)
async def on_click(data):
    # Execute click at coordinates
    return {"success": True}

await sio.connect("http://localhost:8000", namespaces=[namespace])
await sio.emit("init", {"instruction": "Click the button"}, namespace=namespace)

See examples/socketio_client_example.py for a complete implementation.

Documentation

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oagi_core-0.10.2.tar.gz (267.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oagi_core-0.10.2-py3-none-any.whl (87.2 kB view details)

Uploaded Python 3

File details

Details for the file oagi_core-0.10.2.tar.gz.

File metadata

  • Download URL: oagi_core-0.10.2.tar.gz
  • Upload date:
  • Size: 267.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oagi_core-0.10.2.tar.gz
Algorithm Hash digest
SHA256 2d7fb47031cdc2155ea5ea9c06b4b58c0d70091de95a36fa4dedf5d710a09862
MD5 48824a2267a729138469bd03796b12f5
BLAKE2b-256 072f11b7e37049b2faa1e1147a75624c024a93c32287f243c213ca96fc096452

See more details on using hashes here.

File details

Details for the file oagi_core-0.10.2-py3-none-any.whl.

File metadata

  • Download URL: oagi_core-0.10.2-py3-none-any.whl
  • Upload date:
  • Size: 87.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for oagi_core-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b9dd3ade24a1c605d671ed7f35efcd00f729be603a63173c7f92f8177d56750
MD5 493fffb07f7d013068c8a8471b87ae82
BLAKE2b-256 d0c8a1d95327afe6237eaf474d74ba66461e51baaf5948d458cb12be62dbf8a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page