Trace one agent

Note: Create a Langfuse project and copy its public and secret keys. Never commit real keys. pip install praisonaiagents langfuse if import fails.

Keys in the environment

Langfuse receives one trace per agent run when you call obs.langfuse() before start.

Replace the placeholders with your own keys from the Langfuse dashboard.

Example

export LANGFUSE_PUBLIC_KEY=pk-lf-your-public-key
export LANGFUSE_SECRET_KEY=sk-lf-your-secret-key
export OPENAI_API_KEY=your_key_here

Run once, then flush

flush sends buffered spans to Langfuse before the program exits. Open your Langfuse project and look for the new trace.

Example

from praisonaiagents import Agent, obs

provider = obs.langfuse()

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    model="gpt-4o-mini",
)

print(agent.start("What is two plus two?"))
provider.flush()

Example explained

  • obs.langfuse() — Turns on tracing for LLM calls in this process.
  • flush() — Pushes pending traces to Langfuse.

From a YAML file instead

The CLI can trace a full agents.yaml run without the Python script above.

Example

export PRAISONAI_OBSERVE=langfuse
praisonai --observe langfuse run agents.yaml

Reference: documentation