Class: Langfuse::Agent

Inherits:
BaseObservation show all
Defined in:
lib/langfuse/observations.rb

Overview

Observation for tracking agent-based workflows that make decisions and use tools.

Examples:

Block-based API

Langfuse.observe("agent-workflow", as_type: :agent) do |agent|
  agent.input = { task: "Find weather for NYC" }
  # Agent makes decisions and uses tools
  agent.start_observation("tool-call", { tool_name: "weather_api" }, as_type: :tool) do |tool|
    weather = fetch_weather("NYC")
    tool.update(output: weather)
  end
  agent.update(output: { result: "Sunny, 72°F" })
end

Stateful API

agent = Langfuse.start_observation("agent-workflow", {
  input: { task: "Research topic" }
}, as_type: :agent)
# Agent logic here
agent.update(output: { result: "Research complete" })
agent.end

Instance Attribute Summary

Attributes inherited from BaseObservation

#otel_span, #otel_tracer, #type

Instance Method Summary collapse

Methods inherited from BaseObservation

#current_span, #end, #event, #id, #input=, #level=, #metadata=, #output=, #start_observation, #trace_id, #trace_url, #update_trace

Constructor Details

#initialize(otel_span, otel_tracer, attributes: nil) ⇒ Agent

Returns a new instance of Agent.



383
384
385
# File 'lib/langfuse/observations.rb', line 383

def initialize(otel_span, otel_tracer, attributes: nil)
  super(otel_span, otel_tracer, attributes: attributes, type: OBSERVATION_TYPES[:agent])
end

Instance Method Details

#update(attrs) ⇒ self

Parameters:

Returns:

  • (self)


389
390
391
392
# File 'lib/langfuse/observations.rb', line 389

def update(attrs)
  update_observation_attributes(attrs)
  self
end