# OpenAI

AgentiPy provides seamless integration with OpenAI's function calling capabilities, allowing you to create AI agents that can interact with the Solana blockchain. This integration enables developers to build sophisticated AI-driven blockchain applications with natural language interfaces.

### 🚀 Quick Start

```python
import asyncio
from agentipy.agent import SolanaAgentKit
from agents import Agent, Runner, function_tool
from agentipy.tools.get_balance import BalanceFetcher
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Prompt
from solders.pubkey import Pubkey
import os

# Initialize Rich console
console = Console()

# Initialize Solana agent
solana_agent = SolanaAgentKit(
    private_key=os.getenv("PRIVATE_KEY"),
    rpc_url="https://api.mainnet-beta.solana.com"
)

# Create function tools
@function_tool
async def check_sol_balance() -> str:
    """Get the SOL balance for the current wallet."""
    balance = await BalanceFetcher.get_balance(solana_agent)
    return f"SOL balance: {balance} SOL"

# Initialize OpenAI agent
agent = Agent(
    name="Solana Assistant",
    instructions="You are a Solana blockchain assistant that can check balances.",
    tools=[check_sol_balance],
)

# Run the agent
result = await Runner.run(agent, input="Check my SOL balance")
```

### 🛠️ Key Components

#### 1. Function Tools

Function tools are the building blocks of your AI agent's capabilities. They are decorated with `@function_tool` and define the actions your agent can perform.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.agentipy.fun/integrations/openai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
