From 9847aba9c9ed49bf998c7eaa3abdba01efb92c6c Mon Sep 17 00:00:00 2001 From: Dwij Patel Date: Tue, 18 Mar 2025 03:03:20 +0530 Subject: [PATCH] Updated README with updated usage examples for new decorators and session management. Introduce `session`, `agent`, `operation`, `task`, and `workflow` decorators for improved observability. --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7cda3f30a..af2832d30 100644 --- a/README.md +++ b/README.md @@ -140,39 +140,75 @@ Add powerful observability to your agents, tools, and functions with as little c Refer to our [documentation](http://docs.agentops.ai) ```python -# Automatically associate all Events with the agent that originated them -from agentops import track_agent +# Create a session span (root for all other spans) +from agentops.sdk.decorators import session -@track_agent(name='SomeCustomName') -class MyAgent: - ... +@session +def my_workflow(): + # Your session code here + return result ``` ```python -# Automatically create ToolEvents for tools that agents will use -from agentops import record_tool +# Create an agent span for tracking agent operations +from agentops.sdk.decorators import agent -@record_tool('SampleToolName') -def sample_tool(...): - ... +@agent +class MyAgent: + def __init__(self, name): + self.name = name + + # Agent methods here ``` ```python -# Automatically create ActionEvents for other functions. -from agentops import record_action +# Create operation/task spans for tracking specific operations +from agentops.sdk.decorators import operation, task -@agentops.record_action('sample function being record') -def sample_function(...): - ... +@operation # or @task +def process_data(data): + # Process the data + return result ``` ```python -# Manually record any other Events -from agentops import record, ActionEvent +# Create workflow spans for tracking multi-operation workflows +from agentops.sdk.decorators import workflow -record(ActionEvent("received_user_input")) +@workflow +def my_workflow(data): + # Workflow implementation + return result ``` +```python +# Nest decorators for proper span hierarchy +from agentops.sdk.decorators import session, agent, operation + +@agent +class MyAgent: + @operation + def nested_operation(self, message): + return f"Processed: {message}" + + @operation + def main_operation(self): + result = self.nested_operation("test message") + return result + +@session +def my_session(): + agent = MyAgent() + return agent.main_operation() +``` + +All decorators support: +- Input/Output Recording +- Exception Handling +- Async/await functions +- Generator functions +- Custom attributes and names + ## Integrations 🦾 ### OpenAI Agents SDK 🖇️