Quickstart
Start using AgentOps with just 2 lines of code
Install the AgentOps SDK
Add 2 lines of code
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.
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
AGENTOPS_API_KEY=<YOUR API KEY>
Run your agent
Execute your program and visit app.agentops.ai/drilldown to observe your Agent! 🕵️
Clickable link to session
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.
# (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.
# (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.
# End of program
agentops.end_session('Success')
Example Code
Here is the complete code from the sections above
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!
Was this page helpful?