Observability

AgentOps

Using Spectron memory in an agent instrumented by AgentOps.

AgentOps monitors AI agents: session replay, LLM cost tracking, and tool-call telemetry across most agent frameworks. It is complementary to Spectron: AgentOps observes the run, while Spectron gives the agent memory. This guide uses both together with the Python SDK (surrealdb).

Note

This is an integration guide. AgentOps and Spectron are separate services; AgentOps instruments the agent, and Spectron's calls show up in the captured session.

pip install agentops surrealdb openai
export AGENTOPS_API_KEY="..."
export SPECTRON_ENDPOINT="https://api.spectron.example"
export SPECTRON_CONTEXT="acme-prod"
export SPECTRON_API_KEY="sk-spec-..."

agentops.init() auto-instruments supported LLM and framework calls. Use the Spectron client for recall and storage inside the instrumented run:

import os
import agentops
from openai import OpenAI
from surrealdb import Spectron

agentops.init(os.environ["AGENTOPS_API_KEY"])

llm = OpenAI()
memory = Spectron(
    endpoint=os.environ["SPECTRON_ENDPOINT"],
    context=os.environ["SPECTRON_CONTEXT"],
    api_key=os.environ["SPECTRON_API_KEY"],
)
scope = ["org/acme/user/alice"]

def answer(user_message: str) -> str:
    block = memory.query_context(user_message, k=8, scope=scope)

    completion = llm.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": f"You are a helpful assistant.\n\n## Memory\n{block}"},
            {"role": "user", "content": user_message},
        ],
    )
    reply = completion.choices[0].message.content

    memory.remember_many(
        [{"role": "user", "content": user_message}, {"role": "assistant", "content": reply}],
        scope=scope,
    )
    return reply

The model call is captured in the AgentOps session automatically. To attribute the Spectron operations too, wrap them in an AgentOps operation span (@agentops.operation) so recall and storage appear in the session timeline.

Pass a scope on every Spectron call to isolate memory. A scope is a slash path or an array of paths, for example ["org/acme/user/alice"]. Register paths with spectron scopes create before first use.

  • Python SDK: the full client surface

  • Agent frameworks: AgentOps also instruments CrewAI, AutoGen, and others that have first-party Spectron adapters

Was this page helpful?