--- title: "Quickstart" description: "Start using AgentOps with just 2 lines of code" --- import CodeTooltip from '/snippets/add-code-tooltip.mdx' import EnvTooltip from '/snippets/add-env-tooltip.mdx' The AgentOps app is open source—explore the code in our GitHub app directory. ```bash pip pip install agentops ``` ```bash poetry poetry add agentops ``` Get an AgentOps API key [here](https://app.agentops.ai/settings/projects) ```python python import agentops agentops.init() ``` Execute your program and visit [app.agentops.ai/drilldown](https://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
{/* Intentionally blank div for newline */} [Give us a star](https://github.com/AgentOps-AI/agentops) if you liked AgentOps! (you may be our 3,000th 😊) ## More basic functionality You can instrument functions inside your code with the `@operation` decorator, which will create spans that track function execution, parameters, and return values. These operations will be displayed in your session visualization alongside LLM calls. ```python python # Instrument a function as an operation from agentops.sdk.decorators import operation @operation def process_data(data): # Your function logic here result = data.upper() return result ``` If you use specific named agents within your system, you can create agent spans that contain all downstream operations using the `@agent` decorator. ```python python # Create an agent class from agentops.sdk.decorators import agent, operation @agent class MyAgent: def __init__(self, name): self.name = name @operation def perform_task(self, task): # Agent task logic here return f"Completed {task}" ``` Create a session to group all your agent operations by using the `@session` decorator. Sessions serve as the root span for all operations. ```python python # Create a session from agentops.sdk.decorators import session @session def my_workflow(): # Your session code here agent = MyAgent("research-agent") result = agent.perform_task("data analysis") return result # Run the session my_workflow() ``` ## Example Code Here is the complete code from the sections above ```python python import agentops from agentops.sdk.decorators import session, agent, operation # Initialize AgentOps agentops.init() # Create an agent class @agent class MyAgent: def __init__(self, name): self.name = name @operation def perform_task(self, task): # Agent task logic here return f"Completed {task}" # Create a session @session def my_workflow(): # Your session code here agent = MyAgent("research-agent") result = agent.perform_task("data analysis") return result # Run the session my_workflow() ``` 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 operations. AgentOps is a lot more powerful this way! ## Explore our more advanced functionality! Record all of your operations the way AgentOps intends. Associate operations with specific named agents.