Skip to content

Commit abd719f

Browse files
committed
feat: add multi-agent sample and tool spans
1 parent 32c7320 commit abd719f

File tree

8 files changed

+851
-3
lines changed

8 files changed

+851
-3
lines changed

instrumentation-genai/opentelemetry-instrumentation-langchain/examples/manual/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def main():
2121

2222
# ChatOpenAI
2323
llm = ChatOpenAI(
24-
model="gpt-3.5-turbo",
24+
model="gpt-4.1",
2525
temperature=0.1,
2626
max_tokens=100,
2727
top_p=0.9,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copy this file to .env and update values before running the sample.
2+
3+
# Required OpenAI API key
4+
OPENAI_API_KEY=sk-YOUR_API_KEY
5+
6+
# Optional: override default model (defaults to gpt-4o-mini)
7+
# OPENAI_MODEL=gpt-4o-mini
8+
9+
# OTLP exporter configuration (update for your collector)
10+
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
11+
# OTEL_EXPORTER_OTLP_PROTOCOL=grpc
12+
13+
# Traces will use this service.name
14+
OTEL_SERVICE_NAME=opentelemetry-python-langchain-multi-agent
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Multi-Agent Travel Planner Sample
2+
=================================
3+
4+
This example shows how to orchestrate a small team of LangChain agents with
5+
`LangGraph <https://python.langchain.com/docs/langgraph/>`_ while the
6+
OpenTelemetry LangChain instrumentation captures GenAI spans and forwards them
7+
to an OTLP collector.
8+
9+
The graph contains four specialists (coordinator, flights, hotels, activities)
10+
and a final synthesiser node that produces an itinerary. Each specialist relies
11+
on a simple, deterministic tool so you can run the example without any external
12+
travel APIs while still observing tool spans wired up to the agent calls.
13+
14+
Prerequisites
15+
-------------
16+
17+
* Python 3.10+
18+
* An OpenAI API key with access to ``gpt-4o-mini`` (or set ``OPENAI_MODEL`` to a
19+
model that is available to your account)
20+
* A running OTLP collector (gRPC on ``localhost:4317`` by default)
21+
22+
Setup
23+
-----
24+
25+
.. code-block:: bash
26+
27+
cd instrumentation-genai/opentelemetry-instrumentation-langchain/examples/multi_agent_travel_planner
28+
python3 -m venv .venv
29+
source .venv/bin/activate
30+
pip install -r requirements.txt
31+
32+
# Copy the sample environment file and update values as needed.
33+
cp .env.example .env
34+
source .env
35+
36+
Run the sample
37+
--------------
38+
39+
.. code-block:: bash
40+
41+
# From this directory, after activating the virtual environment and sourcing
42+
# your environment variables:
43+
python main.py
44+
45+
The script prints each agent's contribution followed by the final itinerary.
46+
At the same time it streams OTLP traces. You should see:
47+
48+
* A root span named ``invoke_agent travel_multi_agent_planner`` that captures
49+
the overall orchestration, including ``gen_ai.input.messages`` and a preview
50+
of the final plan.
51+
* LangChain instrumentation spans for each agent's LLM invocation with
52+
``gen_ai.provider.name=openai`` and ``service.name`` derived from
53+
``OTEL_SERVICE_NAME``.
54+
55+
Tear down
56+
---------
57+
58+
Deactivate the virtual environment when you are done:
59+
60+
.. code-block:: bash
61+
62+
deactivate

0 commit comments

Comments
 (0)