Skip to main content
OpenTools gives you ready-made toolsets (like Trading) that return consistent outputs. In this quickstart, you’ll create a working agent that connects to your Alpaca account and returns your account information.

Get started

1

Install the SDK

Open your terminal. We’re going to create a folder called my_agent, set up a virtual environment, and install the minimal dependencies.

Use a virtual environment (venv) to ensure this demonstration is not affected by your other cool projects.
2

Add your API keys to your .env file

OpenTools reads credentials from environment variables. For this quickstart we’ll use Alpaca because of its strong capabilities and easy setup.

Model API key

If you already have an OpenAI API key, just add it to your newly-created .env file.
  • Navigate to the OpenAI dashboard (API keys section)
  • Click Create new secret key
  • Copy the key and store it somewhere safe (OpenAI recommends a secure place like your .zshrc but ensure to add it to your .env file)
In this demo we use a .env file and python-dotenv.
If you already export OPENAI_API_KEY globally, you can omit it from .env.

Alpaca API key

If you already have Alpaca keys, skip to the .env section below.
  • Create an Alpaca account (no funding required for paper trading)
  • In the dashboard homepage, find Your API Keys
  • Click Generate New Keys
  • Copy:
    • Key ID
    • Secret Key (shown only once)
Alpaca only shows the Secret Key once. If you lose it, you must generate a new key pair.

Create a .env file

This quickstart uses paper trading by default and never places live trades unless you explicitly enable it. OpenTools does not store keys or manage OAuth. All credentials stay on your machine and are only used when tools are called.

In the same folder as main.py, create a file named .env:

3

Run your first tool call

You’re about to run a small tool loop: the LLM decides which trading tool to call, OpenTools executes it, and the LLM summarises the result.

This example uses paper trading and minimal output. Nothing places orders unless you explicitly ask it to.

Create a main.py

Create a file named main.py and paste the following code:

The code above will add the tools automatically to the LLM context and use a loop to relay tool responses. The tools output structured schemas to ensure interpretability is maximised and relay the information accurately - this has been tested with LLMs as small as 7 billion parameters with clear, correct results.

Run your code

If the model responds without calling tools, ensure you structure yours prompts directly around the tool, here are some examples: “Get my account”, “List positions”, or “Show recent orders”.

If you see a KeyError, one of your environment variables is missing or your .env file is not in the same directory as main.py.

What just happened

When you ran main.py, you gave the model a set of tool definitions from the Trading module. The model decided whether to call any tools. OpenTools executed those calls against Alpaca, then fed the results back to the model until it returned your final answer.

This resulted in token-efficient output for your agent and guaranteed structure if calling the same tool again since intperpretability is standardised for model performance. Learn more about our capabilities and project structuring in the cards below.

Modules

Modules group tools under one domain and define what is normalised. Trading was used in this quickstart.

Models

The Models adapter connects your LLM to the tool surface and runs your tool loop. Trading was used in this quickstart.

Next steps

This quickstart uses OpenAI directly. If you want a framework-managed agent loop, using PydanticAI for example, head to Frameworks or navigate by clicking on the card below.

Frameworks

Frameworks provides a quick introduction to deploying established patterns that are supported by OpenTools, like PydanticAI.