Metadata-Version: 2.2
Name: agentrpc
Version: 0.0.1
Summary: Python SDK for AgentRPC
Project-URL: Homepage, https://agentrpc.com
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.31.0
Requires-Dist: openai>=1.12.0
Provides-Extra: dev
Requires-Dist: ruff>=0.3.0; extra == "dev"
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: python-dotenv>=1.0.0; extra == "dev"

# AgentRPC Python SDK

A universal RPC layer for AI agents. Connect to any function, any language, any framework, in minutes.

> ⚠️ The AgentRPC Python SDK does **not** currently support registering tools.

## Installation

```sh
pip install agentrpc
```

## Registering Tools

### Creating an AgentRPC Client

```python
from agentrpc import AgentRPC

client = AgentRPC(
  api_secret="YOUR_API_SECRET"
)
```


## OpenAI Tools

AgentRPC provides integration with OpenAI's function calling capabilities, allowing you to expose your registered RPC functions as tools for OpenAI models to use.

### `client.openai.get_tools()`

The `get_tools()` method returns your registered AgentRPC functions formatted as OpenAI tools, ready to be passed to OpenAI's API.

```python
import openai

# First register your functions with AgentRPC (Locally or on another machine)

# Then get the tools formatted for OpenAI
tools = await client.openai.get_tools()

# Pass these tools to OpenAI
chat_completion = await openai.chat.completions.create(
  model="gpt-4-1106-preview",
  messages=messages,
  tools=tools,
  tool_choice="auto"
)
```

### `client.openai.execute_tool(tool_call)`

The `execute_tool()` method executes an OpenAI tool call against your registered AgentRPC functions.

```python
# Process tool calls from OpenAI's response
if response_message.tool_calls and len(response_message.tool_calls) > 0:
  for tool_call in response_message.tool_calls:
    try:
      # Execute the tool and add result to messages
      messages.append({
        "role": "tool",
        "tool_call_id": tool_call.id,
        "content": await client.openai.execute_tool(tool_call)
      })
      except Exception as error:
      print(f"Error executing tool {tool_call.function.name}:", error)
        messages.append({
          "role": "tool",
          "tool_call_id": tool_call.id,
          "content": f"Error: {str(error)}"
        })
```

## API

### `AgentRPC(options?)`

Creates a new AgentRPC client.

#### Options:

| Option       | Type   | Default                    | Description          |
| ------------ | ------ | -------------------------- | -------------------- |
| `api_secret` | str    | **Required**               | The API secret key.  |
| `endpoint`   | str    | `https://api.agentrpc.com` | Custom API endpoint. |
