1

Install the AgentOps SDK

pip install agentops
2

Add 2 lines of code

import agentops

# Beginning of program (i.e. main.py, __init__.py)
# IMPORTANT: Must be before any OpenAI, Cohere, Crew, etc constructors are called
# e.g. before client = OpenAI(...)
agentops.init(<INSERT YOUR API KEY HERE>)
Just these two lines and you have magically tracked LLM calls!

After the openai, cohere, or litellm packages have been imported, importing + instantiating the AgentOps client will automatically instrument them, meaning you will be able to see all of your sessions on the AgentOps Dashboard along with the full LLM chat histories, cost, token counts, etc.

At the time of writing, AgentOps offers first class support for openai and cohere models. However we support many more models such as Llama, Mistral, Claude, and Gemini via LiteLLM. Visit our LiteLLM docs to learn more.

3

Set your API key

Retrieve an API Key from your Settings > Projects & API Keys page.

Settings > Projects & API Keys

API keys are tied to individual projects.
A Default Project has been created for you, so just click Copy API Key

Set this API Key in your environment variables

.env
AGENTOPS_API_KEY=<YOUR API KEY>
4

Run your agent

Execute your program and visit app.agentops.ai/drilldown to observe your Agent! 🕵️

After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard

Clickable link to session

Give us a star on GitHub if you found AgentOps helpful (you may be our 2,000th 😊)

More basic functionality

Decorate Functions

You can instrument other functions inside your code with the handy @record_function decorator, which will record an action_type, the parameters, and the returns. You will see these function calls alongside your LLM calls from instantiating the AgentOps client.

python
# (record specific functions)
@agentops.record_function('sample function being record')
def sample_function(...):
  ...

Track Agents

If you use specific named agents within your system, you can tie all downstream Events to a Named Agent with the @track_agent decorator.

python
# (track a named agent)
@agentops.track_agent(name='my-expert-agent')
class sample_agent(...):
  ...

Ending Your Session

Finally, you should end your session by calling .end_session() with whether your session was successful or not (Success|Fail). We suggest setting session state depending on how your agent exits or whether your agent succeeded or not. You can also specify a end state reason, such as user interrupted, ran to completion, or unhandled exception.

python
# End of program
agentops.end_session('Success')

Example Code

Here is the complete code from the sections above

python
import openai
import agentops

# Beginning of program (i.e. main.py, __init__.py)
agentops.init(<INSERT YOUR API KEY HERE>)

# (record specific functions)
@agentops.record_function('sample function being record')
def sample_function(...):
  ...

# (track a named agent)
@agentops.track_agent(name='my-expert-agent')
class sample_agent(...):
  ...

# End of program
agentops.end_session('Success')

Simple Code Example

Jupyter Notebook with sample code that you can run!

That’s all you need to get started! Check out the documentation below to see how you can record other events. AgentOps is a lot more powerful this way!

Explore our more advanced functionality!