Skip to content

OpenAI Agents SDK Integration

The OpenAI Agents SDK provides a powerful framework for building agent workflows. Octagon's specialized financial research agents can be seamlessly integrated with the OpenAI Agents SDK to create sophisticated investment research workflows.

Getting Started with Octagon and the Agents SDK

Prerequisites

To use Octagon agents with the OpenAI Agents SDK, you'll need:

  1. An Octagon API key
  2. An OpenAI API key (for the coordinator agent)
  3. The latest version of the OpenAI Agents SDK

Installation

Install the OpenAI Agents SDK:

bash
pip install openai openai-agents
bash
npm install openai openai-agents

Basic Setup

Here's how to set up a basic integration between Octagon's specialized financial agents and the OpenAI Agents SDK:

Python
import os
from agents import Agent, OpenAIChatCompletionsModel, OpenAIResponsesModel
from openai import AsyncOpenAI

# Set up your API keys
os.environ["OPENAI_API_KEY"] = "<your-openai-api-key>"
os.environ["OCTAGON_API_KEY"] = "<your-octagon-api-key>"

# Configure Octagon client
octagon_client = AsyncOpenAI(
    api_key=os.environ["OCTAGON_API_KEY"],
    base_url="https://api.octagonagents.com/v1",
)

# Create an Octagon specialized agent using Responses API
sec_filings_agent = Agent(
    name="SEC Filings Analysis",
    instructions="You analyze SEC filings to extract financial data, management commentary, risk factors, and other key information from 10-K, 10-Q, and 8-K filings.",
    model=OpenAIResponsesModel(
        model="octagon-sec-agent",
        openai_client=octagon_client,
    ),
)

# Create a coordinator agent with OpenAI
openai_client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
coordinator = Agent(
    name="Research Coordinator",
    instructions="You coordinate financial research by delegating to the SEC Filings Analysis agent when questions involve regulatory filings.",
    model=OpenAIResponsesModel(
        model="gpt-4o",
        openai_client=openai_client,
    ),
    handoffs=[sec_filings_agent],
)
JavaScript
import { Agent } from 'openai-agents';
import { OpenAI } from 'openai';

// Set up your API keys
const OPENAI_API_KEY = '<your-openai-api-key>';
const OCTAGON_API_KEY = '<your-octagon-api-key>';

// Configure Octagon client
const octagonClient = new OpenAI({
  apiKey: OCTAGON_API_KEY,
  baseURL: 'https://api.octagonagents.com/v1',
});

// Create an Octagon specialized agent
const secFilingsAgent = new Agent({
  name: 'SEC Filings Analysis',
  instructions: 'You analyze SEC filings to extract financial data, management commentary, risk factors, and other key information from 10-K, 10-Q, and 8-K filings.',
  model: {
    provider: 'openai',
    model: 'octagon-sec-agent',
    client: octagonClient,
  },
});

// Create a coordinator agent with OpenAI
const openaiClient = new OpenAI({ apiKey: OPENAI_API_KEY });
const coordinator = new Agent({
  name: 'Research Coordinator',
  instructions: 'You coordinate financial research by delegating to the SEC Filings Analysis agent when questions involve regulatory filings.',
  model: {
    provider: 'openai',
    model: 'gpt-4o',
    client: openaiClient,
  },
  handoffs: [secFilingsAgent],
});

Creating Multi-Agent Workflows

The power of the Agents SDK combined with Octagon's specialized agents comes from creating multi-agent workflows. Here's how to set up a workflow with multiple Octagon agents:

Python
import os
from agents import Agent, OpenAIChatCompletionsModel, OpenAIResponsesModel
from openai import AsyncOpenAI

# Set up your API keys
os.environ["OPENAI_API_KEY"] = "<your-openai-api-key>"
os.environ["OCTAGON_API_KEY"] = "<your-octagon-api-key>"

# Configure Octagon client
octagon_client = AsyncOpenAI(
    api_key=os.environ["OCTAGON_API_KEY"],
    base_url="https://api.octagonagents.com/v1",
)

# Configure OpenAI client
openai_client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Create Octagon specialized agents using Responses API
companies_agent = Agent(
    name="Companies Database",
    instructions="You retrieve basic company information from Octagon's companies database.",
    model=OpenAIResponsesModel(
        model="octagon-companies-agent",
        openai_client=octagon_client,
    ),
)

sec_filings_agent = Agent(
    name="SEC Filings Analysis",
    instructions="You analyze SEC filings to extract financial data.",
    model=OpenAIResponsesModel(
        model="octagon-sec-agent",
        openai_client=octagon_client,
    ),
)

# Create a coordinator with access to both agents
coordinator = Agent(
    name="Research Coordinator",
    instructions="""
    You coordinate company research by delegating to specialized Octagon agents:
    1. First, ask the Companies Database agent for basic company information
    2. Then, ask the SEC Filings Analysis agent for insights from regulatory filings
    
    Always explain what you're doing before each handoff.
    """,
    model=OpenAIResponsesModel(
        model="gpt-4o",
        openai_client=openai_client,
    ),
    handoffs=[companies_agent, sec_filings_agent],
)
JavaScript
import { Agent } from 'openai-agents';
import { OpenAI } from 'openai';

// Set up your API keys
const OPENAI_API_KEY = '<your-openai-api-key>';
const OCTAGON_API_KEY = '<your-octagon-api-key>';

// Configure Octagon client
const octagonClient = new OpenAI({
  apiKey: OCTAGON_API_KEY,
  baseURL: 'https://api.octagonagents.com/v1',
});

// Configure OpenAI client
const openaiClient = new OpenAI({ apiKey: OPENAI_API_KEY });

// Create Octagon specialized agents
const companiesAgent = new Agent({
  name: 'Companies Database',
  instructions: 'You retrieve basic company information from Octagon\'s companies database.',
  model: {
    provider: 'openai',
    model: 'octagon-companies-agent',
    client: octagonClient,
  },
});

const secFilingsAgent = new Agent({
  name: 'SEC Filings Analysis',
  instructions: 'You analyze SEC filings to extract financial data.',
  model: {
    provider: 'openai',
    model: 'octagon-sec-agent',
    client: octagonClient,
  },
});

// Create a coordinator with access to both agents
const coordinator = new Agent({
  name: 'Research Coordinator',
  instructions: `
    You coordinate company research by delegating to specialized Octagon agents:
    1. First, ask the Companies Database agent for basic company information
    2. Then, ask the SEC Filings Analysis agent for insights from regulatory filings
    
    Always explain what you're doing before each handoff.
  `,
  model: {
    provider: 'openai',
    model: 'gpt-4o',
    client: openaiClient,
  },
  handoffs: [companiesAgent, secFilingsAgent],
});

Example Workflows

For a complete example of a research workflow using Octagon agents with the OpenAI Agents SDK, see our Research Workflow Example.

Best Practices

When building agent workflows with Octagon and the OpenAI Agents SDK:

  1. Design Clear Handoff Instructions: Give your coordinator agent clear and specific instructions about when to delegate to each specialized agent.

  2. Provide Context Between Agents: When designing multi-step workflows, ensure each agent has enough context about what previous agents discovered.

  3. Use Specialized Agents for Specialized Tasks: Leverage Octagon's domain-specific financial agents for their specialized capabilities rather than asking general-purpose models to handle financial analysis.

  4. Balance Coordination and Execution: The coordinator agent should focus on orchestrating the workflow, while specialized Octagon agents should focus on their specific analyses.

  5. Error Handling: Implement proper error handling to manage API rate limits, timeouts, or unexpected responses.

Next Steps