Getting Started

Quick Start

Set up 2Signal and start tracing your AI agent in under 5 minutes. This guide uses the Python SDK, but the same concepts apply to all supported languages.

1

Install the SDK

Install the 2Signal Python SDK from PyPI. It supports Python 3.9 and above.

bash
pip install twosignal

For TypeScript: npm install twosignal. SDKs are also available for Go, Java, and Ruby.

2

Initialize 2Signal

Add two lines to your application entrypoint. You can find your API key and project ID in the dashboard under Settings > API Keys.

python
1import twosignal23twosignal.init(4 api_key="ts_your_api_key",5 project_id="your_project_id",6)

Once initialized, the SDK automatically traces LLM calls from OpenAI, Anthropic, Cohere, Google, Mistral, Groq, and frameworks like LangChain, LlamaIndex, and CrewAI.

3

Add tracing to your agent

Use the @trace decorator to create a root trace and span() context manager for nested spans. LLM calls within a trace are captured automatically.

python
1from twosignal import trace, span23@trace(name="customer-support-agent")4def handle_ticket(ticket_text: str):5 # Retrieve context6 with span(name="retrieve-context", type="RETRIEVAL"):7 context = search_knowledge_base(ticket_text)89 # Generate response — LLM calls are auto-traced10 response = openai.chat.completions.create(11 model="gpt-4o",12 messages=[13 {"role": "system", "content": f"Context: {context}"},14 {"role": "user", "content": ticket_text},15 ],16 )1718 return response.choices[0].message.content
4

Configure evaluators

In the 2Signal dashboard, enable evaluators that run automatically on every new trace. No code changes needed — evaluators are configured in the dashboard and run asynchronously via background workers.

yaml
# In the 2Signal dashboard, create an evaluator: # # Type: GROUNDEDNESS # Name: "Response Grounded in Context" # Description: "Checks that the agent response is supported by retrieved context" # Enabled: true # # The evaluator runs automatically on every new trace. # No code changes needed.
5

Set up alerts

Configure alert rules to get notified when metrics cross thresholds. Alerts support email, Slack, and custom webhook delivery.

yaml
# Set up alerts in the dashboard: # # Metric: EVAL_PASS_RATE # Condition: < 0.85 over 1 hour # Channel: SLACK # Cooldown: 30 minutes # # You'll be notified when your groundedness # evaluator pass rate drops below 85%.
6

Verify it works

Run your agent and check the 2Signal dashboard. You should see traces with spans, automatic cost and latency tracking, and evaluator scores once your evaluators are configured.

python
# Run your agent handle_ticket("I can't log in to my account") # Check the 2Signal dashboard — you'll see: # - A trace with spans for retrieval + LLM call # - Auto-calculated latency and cost # - Evaluator scores (once configured)

Next steps

Have questions? Join our community.

Connect with other developers and the 2Signal team.

Join Discord