Skip to content

Commit ccede8f

Browse files
shuningcshuning.chenzhirafovod
authored
Adding in-house version of multi-agent-travel-planner (#17)
* Adding in-house version of multi-agent-travel-planner * run one random request once in 15m, with max timeout 10m, no retry * fix chat llm invocations * unify log record utils * emit invocation logs for workflows and agents * system_instructions fix * temporarily change event name for agent/workflow --------- Co-authored-by: shuning.chen <[email protected]> Co-authored-by: Sergey Sergeev <[email protected]>
1 parent d2f4342 commit ccede8f

File tree

10 files changed

+1673
-154
lines changed

10 files changed

+1673
-154
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Use Python 3.12 slim image
2+
FROM python:3.12-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
build-essential \
10+
curl \
11+
git \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Copy the local OpenTelemetry packages first
15+
# Note: Build context should be the repository root for this to work
16+
COPY util/opentelemetry-util-genai /app/util/opentelemetry-util-genai
17+
COPY util/opentelemetry-util-genai-evals /app/util/opentelemetry-util-genai-evals
18+
COPY util/opentelemetry-util-genai-evals-deepeval /app/util/opentelemetry-util-genai-evals-deepeval
19+
COPY util/opentelemetry-util-genai-emitters-splunk /app/util/opentelemetry-util-genai-emitters-splunk
20+
21+
# Install the local OpenTelemetry packages
22+
RUN pip install --no-cache-dir -e /app/util/opentelemetry-util-genai \
23+
&& pip install --no-cache-dir -e /app/util/opentelemetry-util-genai-evals \
24+
&& pip install --no-cache-dir -e /app/util/opentelemetry-util-genai-evals-deepeval \
25+
&& pip install --no-cache-dir -e /app/util/opentelemetry-util-genai-emitters-splunk
26+
27+
# Copy requirements file (for other dependencies)
28+
COPY instrumentation-genai/opentelemetry-instrumentation-langchain/examples/multi_agent_travel_planner/requirements.txt .
29+
30+
# Install Python dependencies
31+
RUN pip install --no-cache-dir -r requirements.txt
32+
33+
# Copy the application code
34+
COPY instrumentation-genai/opentelemetry-instrumentation-langchain/examples/multi_agent_travel_planner/main.py .
35+
# Note: .env.example is optional, only copy if needed
36+
# COPY instrumentation-genai/opentelemetry-instrumentation-langchain/examples/multi_agent_travel_planner/.env.example .env.example
37+
38+
# Create a non-root user for security
39+
RUN useradd --create-home --shell /bin/bash app \
40+
&& chown -R app:app /app
41+
USER app
42+
43+
# Expose port (adjust if your app uses a different port)
44+
EXPOSE 8080
45+
46+
# Health check
47+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
48+
CMD curl -f http://localhost:8080/health || exit 1
49+
50+
# Run the application
51+
CMD ["python", "main.py"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: travel-planner-load-generator
5+
namespace: travel-planner
6+
spec:
7+
schedule: "*/15 * * * *" # Every 15 minutes
8+
jobTemplate:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: load-generator
14+
image: curlimages/curl:latest
15+
command:
16+
- /bin/sh
17+
- -c
18+
- |
19+
echo "Generating travel planning requests..."
20+
21+
# Simple requests without bash-specific syntax
22+
destinations="Tokyo Paris NewYork Sydney Barcelona Dubai London Singapore"
23+
budgets="2000 3000 1500 4000 2500"
24+
durations="3 5 7 10"
25+
26+
# Generate a single random request per run
27+
RAND=$(date +%s)
28+
dest=$(echo $destinations | cut -d' ' -f$((($RAND % 8) + 1)))
29+
budget=$(echo $budgets | cut -d' ' -f$((($RAND % 5) + 1)))
30+
duration=$(echo $durations | cut -d' ' -f$((($RAND % 4) + 1)))
31+
32+
echo "Planning trip to $dest, budget: \$$budget, duration: $duration days"
33+
34+
# Make single request to the travel planner service
35+
curl -X POST http://travel-planner-service.travel-planner.svc.cluster.local/plan \
36+
-H "Content-Type: application/json" \
37+
-d "{
38+
\"destination\": \"$dest\",
39+
\"budget\": $budget,
40+
\"duration\": $duration,
41+
\"travelers\": 2,
42+
\"interests\": [\"sightseeing\", \"food\", \"culture\"]
43+
}" \
44+
--max-time 600 || echo "Request failed"
45+
46+
echo "Load generation completed"
47+
restartPolicy: OnFailure
48+
backoffLimit: 3
49+
successfulJobsHistoryLimit: 3
50+
failedJobsHistoryLimit: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: travel-planner
5+
namespace: travel-planner
6+
labels:
7+
app: travel-planner
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: travel-planner
13+
template:
14+
metadata:
15+
labels:
16+
app: travel-planner
17+
spec:
18+
containers:
19+
- name: travel-planner
20+
image: shuniche855/travel-planner:0.0.2
21+
imagePullPolicy: Always
22+
ports:
23+
- containerPort: 8080
24+
name: http
25+
env:
26+
# Load OpenAI API key from secret
27+
- name: OPENAI_API_KEY
28+
valueFrom:
29+
secretKeyRef:
30+
name: openai-api-keys
31+
key: openai-api-key
32+
# Service Name
33+
- name: OTEL_SERVICE_NAME
34+
value: "opentelemetry-python-langchain-multi-agent-in-house"
35+
# Additional OTEL configuration
36+
- name: OTEL_RESOURCE_ATTRIBUTES
37+
value: "deployment.environment=o11y-inframon-ai"
38+
- name: SPLUNK_OTEL_AGENT
39+
valueFrom:
40+
fieldRef:
41+
fieldPath: status.hostIP
42+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
43+
value: "http://$(SPLUNK_OTEL_AGENT):4317"
44+
- name: OTEL_EXPORTER_OTLP_PROTOCOL
45+
value: "grpc"
46+
- name: HOME
47+
value: "/tmp"
48+
- name: OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
49+
value: "DELTA"
50+
- name: OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED
51+
value: "true"
52+
- name: OTEL_PYTHON_EXCLUDED_URLS
53+
value: "^(https?://)?[^/]+(/health)?$"
54+
- name: OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT
55+
value: "true"
56+
- name: OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT_MODE
57+
value: "SPAN_AND_EVENT"
58+
- name: OTEL_INSTRUMENTATION_GENAI_EVALS_RESULTS_AGGREGATION
59+
value: "true"
60+
- name: OTEL_INSTRUMENTATION_GENAI_EMITTERS
61+
value: "span_metric_event,splunk"
62+
- name: OTEL_INSTRUMENTATION_GENAI_EMITTERS_EVALUATION
63+
value: "replace-category:SplunkEvaluationResults"
64+
- name: OTEL_GENAI_EVAL_DEBUG_SKIPS
65+
value: "true"
66+
- name: OTEL_GENAI_EVAL_DEBUG_EACH
67+
value: "true"
68+
- name: OTEL_INSTRUMENTATION_GENAI_DEBUG
69+
value: "true"
70+
- name: SPLUNK_PROFILER_ENABLED
71+
value: "true"
72+
# Set evaluation wait time to 10 seconds (short enough to avoid health check timeout)
73+
- name: EVAL_WAIT_SECONDS
74+
value: "10"
75+
resources:
76+
requests:
77+
memory: "512Mi"
78+
cpu: "250m"
79+
limits:
80+
memory: "2Gi"
81+
cpu: "1000m"
82+
securityContext:
83+
allowPrivilegeEscalation: false
84+
runAsNonRoot: true
85+
runAsUser: 1000
86+
capabilities:
87+
drop:
88+
- ALL
89+
readOnlyRootFilesystem: false
90+
livenessProbe:
91+
httpGet:
92+
path: /health
93+
port: 8080
94+
initialDelaySeconds: 30
95+
periodSeconds: 10
96+
timeoutSeconds: 5
97+
failureThreshold: 6
98+
readinessProbe:
99+
httpGet:
100+
path: /health
101+
port: 8080
102+
initialDelaySeconds: 5
103+
periodSeconds: 5
104+
restartPolicy: Always
105+
---
106+
apiVersion: v1
107+
kind: Service
108+
metadata:
109+
name: travel-planner-service
110+
namespace: travel-planner
111+
spec:
112+
selector:
113+
app: travel-planner
114+
ports:
115+
- name: http
116+
port: 80
117+
targetPort: 8080
118+
type: ClusterIP

0 commit comments

Comments
 (0)