Custom Agents

Integrate Sentrial with your custom agent implementation.

Manual Tracking

For custom agents or frameworks not covered by our integrations, use the SDK directly to track events.

from sentrial import SentrialClient

client = SentrialClient(api_key="...", project_id="...")
session_id = client.create_session(name="Custom Agent")

# Your custom agent loop
while not done:
    # Track decision
    client.track_decision(
        session_id=session_id,
        reasoning="Analyzing user query...",
        alternatives=["Search", "Direct answer"],
        chosen="Search",
        confidence=0.8
    )
    
    # Track tool call
    result = my_search_tool(query)
    client.track_tool_call(
        session_id=session_id,
        tool_name="search",
        tool_input={"query": query},
        tool_output=result
    )
    
    # Track LLM call
    response = llm.generate(prompt)
    client.track_llm_call(
        session_id=session_id,
        prompt=prompt,
        response=response,
        model="gpt-4"
    )

client.close_session(session_id)

Framework-Specific Guides

CrewAI

Track CrewAI agents and tasks:

from crewai import Agent, Task, Crew
from sentrial import SentrialClient

client = SentrialClient(api_key="...", project_id="...")
session_id = client.create_session(name="CrewAI Agent")

# Wrap your tasks to track execution
def tracked_task(task_func):
    def wrapper(*args, **kwargs):
        client.track_tool_call(
            session_id=session_id,
            tool_name=task_func.__name__,
            tool_input=kwargs,
            tool_output=result := task_func(*args, **kwargs)
        )
        return result
    return wrapper

@tracked_task
def research_task():
    # Your task implementation
    pass

AutoGPT

Integrate with AutoGPT loops:

# In your AutoGPT plugin or main loop
from sentrial import SentrialClient

class SentrialTrackingPlugin:
    def __init__(self):
        self.client = SentrialClient(api_key="...", project_id="...")
        self.session_id = None
    
    def on_planning(self, plan):
        if not self.session_id:
            self.session_id = self.client.create_session(
                name="AutoGPT Session"
            )
        
        self.client.track_decision(
            session_id=self.session_id,
            reasoning=plan.reasoning,
            alternatives=plan.alternatives,
            chosen=plan.chosen_action
        )

Custom Python Agent

Example of a simple custom agent with Sentrial tracking:

class MyAgent:
    def __init__(self, sentrial_client, session_id):
        self.client = sentrial_client
        self.session_id = session_id
    
    def run(self, task):
        # Track the overall goal
        self.client.track_decision(
            session_id=self.session_id,
            reasoning=f"Starting task: {task}",
            chosen="begin_execution"
        )
        
        # Your agent logic
        steps = self.plan(task)
        for step in steps:
            result = self.execute_step(step)
            
            # Track each step
            self.client.track_tool_call(
                session_id=self.session_id,
                tool_name=step.tool,
                tool_input=step.input,
                tool_output=result
            )
        
        return self.summarize()

Best Practices

✓ DO

  • Track major decisions and reasoning steps
  • Include context in tool call metadata
  • Use consistent naming for tools
  • Close sessions when complete

✗ DON'T

  • Track every single function call (too noisy)
  • Send PII or sensitive data to Sentrial
  • Block on tracking calls (use async when possible)
  • Skip error tracking

Error Handling

Always wrap tracking calls to prevent failures from breaking your agent:

def safe_track(func, *args, **kwargs):
    """Wrapper to prevent tracking failures from breaking agent."""
    try:
        return func(*args, **kwargs)
    except Exception as e:
        print(f"Sentrial tracking error: {e}")
        # Continue agent execution
        return None

# Use it
safe_track(
    client.track_tool_call,
    session_id=session_id,
    tool_name="search",
    ...
)

Need an Integration?

Using a framework we don't support yet? Let us know and we'll build an integration.

Request Integration →