Novita AI Now Supports OpenAI Agents SDK!

novita ai& OpenAI Agent SDK

OpenAI Agents SDK‘s tracing system provides visibility into AI workflows, capturing important events to help developers monitor and debug their applications effectively.

What is OpenAI Agents SDK?

OpenAI Agents SDK is a Python toolkit that simplifies AI agent development. This production-ready evolution of OpenAI’s SWARM project provides features for building intelligent, collaborative, and secure AI systems. At its core are LLM-based agents configurable with specific instructions and tools, supporting custom roles and compatible with both OpenAI models (o1, o3-mini, gpt-4o) and third-party models with OpenAI-compatible APIs.

Key Features of OpenAI Agents SDK

Tools and Functional Extensions:

  • Function Calling: Convert Python functions into tools using the @function_tool decorator, with automatic schema generation and Pydantic validation
  • Built-in Agent Loop: Handle tool calls, result feedback, and task loops for seamless interaction between agents and LLMs
  • Task Handoffs: Allow agents to delegate tasks to other specialized agents, enabling multi-agent collaboration

Security and Monitoring Mechanisms:

  • Guardrails: Input screening prevents harmful content, while output validation ensures response quality and appropriateness
  • Tracing Tools: Built-in tracing functionality visualizes and monitors the entire agent flow, aiding debugging and optimization

Developer-Friendly Features:

  • Python-Native Methods: Leverage Python language features for agent orchestration and chaining, reducing the need to learn new abstractions
  • Highly Customizable: Provides custom tools, structured output types, and external LLM provider integration capabilities
  • Lightweight Design: Simple yet powerful set of primitives requiring minimal learning curve

Benefits of OpenAI Agents SDK

Development Efficiency

  • Simplifies setup processes, streamlines agent application development, and lowers the barrier to entry for AI agent development

Enhanced System Capabilities:

  • Supports complex task execution and efficient multi-agent collaboration
  • Creates specialized collaborative systems to solve complex problems
  • Integrates external LLM models for greater flexibility

Security and Reliability:

  • Guardrails ensure safe AI interactions
  • Enhances AI agent system reliability and appropriate behavior
  • Simplifies preparation of AI agent applications for production environments

Analysis and Optimization:

  • Tracing system provides insights into agent behavior
  • Improves user pattern analysis and bottleneck identification
  • Enhances debugging and workflow optimization capabilities

An Example of OpenAI Agents SDK

Flowchart

Step 1: Setup the Agent

Initialize the agent by creating a virtual assistant named AccountingAssistant with clear instructions for its functionality.

Step 2: Integrate Tools

Integrate essential tools, including:

  • Web Search Tool: Retrieve tax updates.
  • API Calls: Analyze financial statements.
  • File Search Tool: Locate relevant documents.

Step 3: Define Tasks

Break down the workflow into specific tasks:

  • Task 1: Retrieve the latest tax updates.
  • Task 2: Analyze financial data using an API.
  • Task 3: Generate reports based on the latest data.

Step 4: Execute Tasks

Run tasks sequentially or in parallel. For example:

Runner.run_sync(agent, "Generate a report based on the latest tax laws and financial data.")

Step 5: Monitor and Debug

Use tracing tools to monitor the execution of tasks and identify potential issues for debugging.

How to Integrate Novita AI with OpenAI Agents SDK?

1. Set up your Python environment and install the Agents SDK.

python -m venv env
source env/bin/activate
pip install openai-agents

2. Set up your Novita API key.

get api key

3. An Example of Handoffs

import os
from openai import AsyncOpenAI
from agents import (
    Agent,
    Runner,
    set_default_openai_api,
    set_default_openai_client,
    set_tracing_disabled,
)

BASE_URL = "https://api.novita.ai/v3/openai"
API_KEY = os.getenv("NOVITA_API_KEY")
MODEL_NAME = os.getenv("MODEL_NAME")

# Because Novita not support the responses API so we use the chat completions API instead.
set_default_openai_api("chat_completions")
set_default_openai_client(AsyncOpenAI(base_url=BASE_URL, api_key=API_KEY))
# Disable tracing for this example
# Refer to https://openai.github.io/openai-agents-python/tracing/#external-tracing-processors-list to use the custom spans.
set_tracing_disabled(disabled=True)

agent = Agent(name="Assistant",
              instructions="You are a helpful assistant", model=MODEL_NAME)

result = Runner.run_sync(
    agent, "Write a haiku about recursion in programming.")
print(result.final_output)

# Code within the code,
# Functions calling themselves,
# Infinite loop's dance.

With flexible tracing capabilities, developers can track agent behavior through both built-in functionality and third-party integrations, ensuring better performance and reliability.

Frequently Asked Questions

Which LLM models can I use with OpenAI Agents SDK ?

Compatible with OpenAI models (o1, o3-mini, gpt-4o) and third-party models with OpenAI-compatible APIs like Novita AI.

How does OpenAI Agents SDK handle tool integration?

Convert Python functions into tools using the @function_tool decorator with automatic schema generation and Pydantic validation.

Is the OpenAI Agents SDK suitable for production environments?

Yes, it includes security features like guardrails, comprehensive tracing, and monitoring capabilities.

Novita AI is an AI cloud platform that offers developers an easy way to deploy AI models using our simple API, while also providing an affordable and reliable GPU cloud for building and scaling.

Recommend Reading


Discover more from Novita

Subscribe to get the latest posts sent to your email.

Leave a Comment

Scroll to Top

Discover more from Novita

Subscribe now to keep reading and get access to the full archive.

Continue reading