### Full Agent Setup with OTel and Tools Source: https://docs.galileo.ai/how-to-guides/experiments/otel-experiment/otel-experiment This comprehensive example demonstrates setting up an agent with OpenTelemetry instrumentation, defining tools, and configuring an OpenAI client. It includes the OTel setup, framework instrumentation, tool definition, agent creation, and an asynchronous function to run the agent. ```python import asyncio import os from typing import Any from agent_framework import openai, tool from agent_framework.observability import enable_instrumentation from galileo.otel import GalileoSpanProcessor, add_galileo_span_processor from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider # ── OTel Setup ─────────────────────────────────────────────────────────────── tracer_provider = TracerProvider() galileo_processor = GalileoSpanProcessor() add_galileo_span_processor(tracer_provider, galileo_processor) trace.set_tracer_provider(tracer_provider) enable_instrumentation(enable_sensitive_data=True) # ── Tools ──────────────────────────────────────────────────────────────────── @tool(approval_mode="never_require") def lookup_account(account_id: str) -> str: """Look up account details by account ID.""" accounts = { "ACCT-1001": {"name": "Alice", "plan": "Premium", "balance": 120.00}, "ACCT-1002": {"name": "Bob", "plan": "Basic", "balance": 45.50}, } account = accounts.get(account_id) if account: return f"Account {account_id}: {account}" return f"Account {account_id} not found." # ── Agent ──────────────────────────────────────────────────────────────────── client = openai.OpenAIChatClient(model_id="gpt-4.1-mini") agent = client.as_agent( name="BillingAgent", instructions="You are a helpful billing assistant. Use the lookup_account " "tool to find customer account details.", tools=[lookup_account], ) # ── Experiment Entry Point ─────────────────────────────────────────────────── async def _run_agent_async(user_message: str) -> str: session = agent.create_session() result = await agent.run(user_message, session=session) return getattr(result, "text", str(result)).strip() def run_agent(input_data: Any) -> str: """Called by Galileo's run_experiment for each dataset row.""" if isinstance(input_data, str): user_message = input_data elif isinstance(input_data, dict): user_message = input_data.get("input", "") else: raise TypeError(f"Unsupported input type: {type(input_data)!r}") return asyncio.run(_run_agent_async(user_message)) ``` -------------------------------- ### Install Dependencies and Run Services Source: https://docs.galileo.ai/sdk-api/logging/distributed-tracing-otel Installs project dependencies and starts two agent services (Agent B on port 8001, Agent A on port 8000). It then sends a POST request to Agent A to initiate a distributed trace. ```bash pip install -r requirements.txt # Terminal 1 uvicorn agent_b:app --port 8001 # Terminal 2 uvicorn agent_a:app --port 8000 # Terminal 3 curl -s -X POST http://localhost:8000/ask \ -H "Content-Type: application/json" \ -d '{"question": "Tell me about Voyager 1."}' | jq ``` -------------------------------- ### Start a Trace with Galileo Logger Source: https://docs.galileo.ai/references/faqs/faqs This example demonstrates how to start a trace using the Galileo logger, which can help in troubleshooting logging issues. ```python galileo_context or create a new Trace in your application. ``` -------------------------------- ### Full TypeScript Example with Manual Logging Source: https://docs.galileo.ai/how-to-guides/basics/manual-span-creation/manual-span-creation A complete TypeScript example showing manual logger setup, trace initiation, API interaction, and log flushing. ```typescript import { OpenAI } from "openai"; import dotenv from "dotenv"; import { GalileoLogger } from "galileo"; dotenv.config(); const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const prompt = "Explain the following topic succinctly: Newton's First Law"; async function promptOpenAI(prompt: string, logger: GalileoLogger) { const response = await openai.chat.completions.create({ model: "gpt-4.1-mini", messages: [{ content: prompt, role: "user" }], }); return response.choices[0].message.content; } // Create a logger instance const logger = new GalileoLogger(); // Start a new trace logger.startTrace({ input: "Newton's First Law Trace" }); const response = await promptOpenAI(prompt, logger); console.log(response); logger.conclude({ output: response ?? ""}); logger.flush(); ``` -------------------------------- ### Complete Example: Setting up Galileo Tracing and Spans Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/start-galileo-span This example shows the complete setup for Galileo OpenTelemetry tracing, including initializing the `TracerProvider`, adding a `GalileoSpanProcessor`, and using `start_galileo_span` to create nested spans for workflow and retrieval operations. It also demonstrates setting custom attributes on spans. ```Python from galileo.otel import ( start_galileo_span, GalileoSpanProcessor, add_galileo_span_processor, ) from galileo_core.schemas.logging.span import WorkflowSpan, RetrieverSpan from galileo_core.schemas.shared.document import Document from opentelemetry.sdk.trace import TracerProvider def setup_tracing(): """Initialize Galileo OpenTelemetry tracing.""" tracer_provider = TracerProvider() processor = GalileoSpanProcessor( project="my-ai-application", logstream="production", ) add_galileo_span_processor(tracer_provider, processor) return processor def search_knowledge_base(query: str) -> list[str]: """Search with automatic span creation.""" retriever_span = RetrieverSpan(name="knowledge-base-search", input=query) with start_galileo_span(retriever_span) as span: results = ["Result 1", "Result 2", "Result 3"] retriever_span.output = [Document(content=r) for r in results] # Add custom metrics span.set_attribute("search.result_count", len(results)) return results def main(): processor = setup_tracing() # Create a parent span for the workflow workflow_span = WorkflowSpan(name="user-query-workflow") with start_galileo_span(workflow_span) as span: span.set_attribute("user.query", "What is machine learning?") # Nested retriever span results = search_knowledge_base("What is machine learning?") print(f"Found {len(results)} results") if __name__ == "__main__": main() ``` -------------------------------- ### Install Luna Studio SDK with Data Generation and Training Extras Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the core SDK with data generation and training capabilities. This is the recommended base installation. ```bash pip install "galileo-luna-ft[data-generation,training]" ``` -------------------------------- ### Clone SDK Examples Repository Source: https://docs.galileo.ai/cookbooks/features/integrations/langgraph-otel-cookbook Clone the repository containing SDK examples and navigate to the LangGraph-OTel directory. ```bash git clone https://github.com/rungalileo/sdk-examples cd sdk-examples/python/agent/langgraph-otel ``` -------------------------------- ### Install dependencies (uv) Source: https://docs.galileo.ai/cookbooks/use-cases/agent-langchain Install project dependencies using uv from the requirements.txt file. ```bash uv pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies Source: https://docs.galileo.ai/how-to-guides/third-party-integrations/openai-agent-integration Install the Galileo SDK and other necessary dependencies using pip. ```Bash pip install galileo openai-agents python-dotenv ``` -------------------------------- ### Install Dependencies Source: https://docs.galileo.ai/getting-started/quickstart Install the necessary packages for Galileo, TypeScript, and Anthropic SDK. ```bash npm install galileo tsx dotenv @anthropic-ai/sdk ``` -------------------------------- ### Install dependencies (pip) Source: https://docs.galileo.ai/cookbooks/use-cases/agent-langchain Install project dependencies using pip from the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies (Python) Source: https://docs.galileo.ai/getting-started/quickstart Install the necessary Python packages for Galileo, Google GenAI, and environment variable management. ```bash pip install galileo python-dotenv google-genai ``` -------------------------------- ### Install OpenTelemetry Packages Source: https://docs.galileo.ai/sdk-api/third-party-integrations/a2a Install the necessary OpenTelemetry packages for core functionality and OTLP export to Galileo. ```bash pip install opentelemetry-api opentelemetry-sdk \ opentelemetry-exporter-otlp ``` -------------------------------- ### Set Up Virtual Environment and Install Dependencies (Windows) Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Creates and activates a virtual environment using uv, then installs project dependencies from requirements.txt on Windows. ```bash uv venv source .venv\Scripts\activate uv pip install -r requirements.txt ``` -------------------------------- ### Get Integration Help from Galileo MCP Source: https://docs.galileo.ai/getting-started/mcp/setup-galileo-mcp Ask the MCP server for assistance with integrating Galileo into your LangChain application. The server will provide code examples and setup instructions. ```text How do I integrate Galileo with my LangChain application in Python? ``` -------------------------------- ### Clone the Starter Project Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Clone the repository containing the startup simulator example project. ```bash git clone https://github.com/rungalileo/sdk-examples ``` -------------------------------- ### Start a basic trace Source: https://docs.galileo.ai/sdk-api/logging/galileo-logger Initiates a new trace, to which all subsequent spans will be added. This example shows starting a trace with a required input parameter. ```Python # Start a basic trace trace = logger.start_trace(input="User query") ``` ```TypeScript // Start a basic trace const trace = galileoLogger.startTrace({ input: "User query" }); ``` -------------------------------- ### Install necessary packages Source: https://docs.galileo.ai/sdk-api/third-party-integrations/a2a Install the required Python packages for A2A integration, Galileo, LangChain, and related libraries. This command sets up your environment for the full example. ```bash pip install galileo-a2a "galileo[otel]" langchain langchain-openai langgraph \ opentelemetry-instrumentation-langchain uvicorn starlette sse-starlette \ python-dotenv ``` -------------------------------- ### Set Up Virtual Environment and Install Dependencies (MacOS/Linux) Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Creates and activates a virtual environment using uv, then installs project dependencies from requirements.txt on MacOS/Linux. ```bash uv venv source .venv/bin/activate uv pip install -r requirements.txt ``` -------------------------------- ### Environment Setup and Initialization Source: https://docs.galileo.ai/how-to-guides/rag/preventing-out-of-context-information Sets up the Python environment with necessary libraries, loads environment variables, initializes Galileo logging, and creates an OpenAI client. Ensure GALILEO_API_KEY and OPENAI_API_KEY are set in your .env file. ```python import os from dotenv import load_dotenv from galileo import openai, log, galileo_context import questionary load_dotenv() # Check if Galileo logging is enabled logging_enabled = os.environ.get("GALILEO_API_KEY") is not None galileo_context.init(project="out-of-context", log_stream="dev") # Initialize OpenAI client client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) ``` -------------------------------- ### Start OpenTelemetry Processor (Manual OTLP) Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/vercel-ai Configure and start the OpenTelemetry SDK with manual OTLP exporter setup. Update the `galileoEndpoint` if using a custom Galileo deployment. ```typescript import { NodeSDK } from '@opentelemetry/sdk-node'; import { AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node'; import { OTLPHttpProtoTraceExporter } from '@vercel/otel'; import { env } from 'process'; ``` -------------------------------- ### Start OpenTelemetry Processor (GalileoSpanProcessor) Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/vercel-ai Initialize and start the OpenTelemetry SDK with the GalileoSpanProcessor for automatic OTLP configuration using environment variables. No manual endpoint or header setup is needed. ```typescript import { NodeSDK } from '@opentelemetry/sdk-node'; import { AlwaysOnSampler } from '@opentelemetry/sdk-trace-node'; import { GalileoSpanProcessor } from 'galileo'; const sdk = new NodeSDK({ spanProcessors: [new GalileoSpanProcessor()], sampler: new AlwaysOnSampler(), }); sdk.start(); ``` -------------------------------- ### Copy .env.example to .env Source: https://docs.galileo.ai/cookbooks/features/integrations/langgraph-otel-cookbook Copy the example environment file to create your local configuration file. ```bash cp .env.example .env ``` -------------------------------- ### Complex Trace Example (TypeScript) Source: https://docs.galileo.ai/sdk-api/logging/galileo-logger This example demonstrates creating a complex trace with multiple spans, including starting a trace, adding retriever and LLM spans, concluding, and flushing. Requires GalileoLogger initialization. ```typescript import { GalileoLogger } from "galileo"; const galileoLogger = new GalileoLogger({ projectName: "my-project", logStreamName: "my-log-stream", }); // Start a trace for a user query const trace = galileoLogger.startTrace({ input: "Who's a good bot?", name: "User Query", tags: ["bot-interaction"] }); // Add a retriever span for document retrieval galileoLogger.addRetrieverSpan({ input: "Who's a good bot?", output: ["Research shows that I am a good bot."], name: "Document Retrieval", durationNs: 1000000 }); // Add an LLM span for generating a response galileoLogger.addLlmSpan({ input: "Who's a good bot?", output: "I am!", model: "gpt-4.1-mini", name: "Response Generation", numInputTokens: 25, numOutputTokens: 3, totalTokens: 28, durationNs: 1000000 }); // Conclude the trace galileoLogger.conclude({ output: "I am!", durationNs: 2000000 }) // Flush the trace to Galileo galileoLogger.flush(); ``` -------------------------------- ### Complex Trace Example (Python) Source: https://docs.galileo.ai/sdk-api/logging/galileo-logger This example demonstrates creating a complex trace with multiple spans, including starting a trace, adding retriever and LLM spans, concluding, and flushing. Requires GalileoLogger initialization. ```python from galileo import GalileoLogger logger = GalileoLogger(project="my-project", log_stream="my-log-stream") # Start a trace for a user query trace = logger.start_trace( input="Who's a good bot?", name="User Query", tags=["bot-interaction"] ) # Add a retriever span for document retrieval logger.add_retriever_span( input="Who's a good bot?", output=["Research shows that I am a good bot."], name="Document Retrieval", duration_ns=1000000 ) # Add an LLM span for generating a response logger.add_llm_span( input="Who's a good bot?", output="I am!", model="gpt-4o", name="Response Generation", num_input_tokens=25, num_output_tokens=3, total_tokens=28, duration_ns=1000000 ) # Conclude the trace logger.conclude(output="I am!", duration_ns=2000000) # Flush the trace to Galileo logger.flush() ``` -------------------------------- ### Environment Setup and Imports Source: https://docs.galileo.ai/how-to-guides/agentic-ai/basic-example Imports necessary libraries, loads environment variables, initializes console output, and sets up the OpenAI client with Galileo integration. This is the initial setup for the application. ```python import os from galileo import log, galileo_context, openai # Import Galileo components import json from pydantic import BaseModel, Field from typing import List, Dict, Any, Optional from dotenv import load_dotenv from rich.console import Console import questionary load_dotenv() # Initialize console and OpenAI client console = Console() client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) ``` -------------------------------- ### Clone the repository Source: https://docs.galileo.ai/cookbooks/use-cases/agent-langchain Clone the SDK examples repository and navigate to the LangChain agent directory. ```bash git clone https://github.com/rungalileo/sdk-examples.git cd sdk-examples/python/agent/langchain-agent ``` -------------------------------- ### Full Strands Agent Example with Galileo Telemetry Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/strands-agents A complete Python example demonstrating Strands Agent setup with Galileo's OpenTelemetry backend. Includes environment variable loading, telemetry configuration, a custom tool, and agent interaction. ```Python import os from strands import Agent, tool from strands.telemetry import StrandsTelemetry from strands_tools import calculator, current_time # Load environment variables from the .env file from dotenv import load_dotenv load_dotenv(override=True) # Export the Galileo OTel API endpoint for OTel # Export the Galileo OTel API endpoint for OTel os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.environ.get( "GALILEO_API_ENDPOINT", "https://api.galileo.ai/otel/traces" ) # Export the Galileo OTel headers pointing to the correct API key, # # project, and log stream headers = { "Galileo-API-Key": os.environ["GALILEO_API_KEY"], "project": os.environ["GALILEO_PROJECT"], "logstream": os.environ["GALILEO_LOG_STREAM"], } os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = ",".join( [f"{k}={v}" for k, v in headers.items()] ) # Setup telemetry for the Strands agent using Galileo as the OTel backend strands_telemetry = StrandsTelemetry() strands_telemetry.setup_otlp_exporter() # Define a custom tool as a Python function using the @tool decorator @tool def letter_counter(word: str, letter: str) -> int: """ Count occurrences of a specific letter in a word. Args: word (str): The input word to search in letter (str): The specific letter to count Returns: int: The number of occurrences of the letter in the word """ if not isinstance(word, str) or not isinstance(letter, str): return 0 if len(letter) != 1: raise ValueError("The 'letter' parameter must be a single char") return word.lower().count(letter.lower()) # Create an agent with tools from the community-driven strands-tools # package as well as our custom letter_counter tool agent = Agent(tools=[calculator, current_time, letter_counter]) # Ask the agent a question that uses the available tools message = """ I have 4 requests: 1. What is the time right now? 2. Calculate 3111696 / 74088 3. Tell me how many letter R's are in the word "strawberry" 🍓 """ agent(message) ``` -------------------------------- ### Get Paginated Experiments Source: https://docs.galileo.ai/sdk-api/typescript/reference/README/classes/GalileoApiClient Retrieves experiments with pagination options. Supports including counts, setting a limit, and specifying a starting token. ```typescript getExperimentsPaginated(options?: object): Promise; ``` -------------------------------- ### Create Project Files Source: https://docs.galileo.ai/how-to-guides/third-party-integrations/openai-agent-integration Create a new blank application file and a .env file in your project folder. ```Python homework-assistant/ │── app.py │── .env ``` -------------------------------- ### OpenAPI Specification for Get Dataset Content Source: https://docs.galileo.ai/api-reference/datasets/get-dataset-content This OpenAPI 3.1.0 specification defines the GET /v2/datasets/{dataset_id}/content endpoint. It includes parameters for dataset ID, starting token, and limit, as well as response schemas for successful retrieval and validation errors. ```yaml openapi: 3.1.0 info: title: FastAPI version: 0.1.0 servers: - url: https://api.galileo.ai description: Galileo Public APIs - galileo-v2 security: [] paths: /v2/datasets/{dataset_id}/content: get: tags: - datasets summary: Get Dataset Content operationId: get_dataset_content_v2_datasets__dataset_id__content_get parameters: - name: dataset_id in: path required: true schema: type: string format: uuid4 title: Dataset Id - name: starting_token in: query required: false schema: type: integer title: Starting Token default: 0 - name: limit in: query required: false schema: type: integer title: Limit default: 100 responses: '200': description: Successful Response content: application/json: schema: $ref: '#/components/schemas/DatasetContent' '422': description: Validation Error content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' security: - APIKeyHeader: [] - OAuth2PasswordBearer: [] - HTTPBasic: [] components: schemas: DatasetContent: properties: starting_token: type: integer title: Starting Token default: 0 limit: type: integer title: Limit default: 100 paginated: type: boolean title: Paginated default: false next_starting_token: anyOf: - type: integer - type: 'null' title: Next Starting Token column_names: items: type: string type: array title: Column Names warning_message: anyOf: - type: string - type: 'null' title: Warning Message rows: items: $ref: '#/components/schemas/DatasetRow' type: array title: Rows type: object title: DatasetContent HTTPValidationError: properties: detail: items: $ref: '#/components/schemas/ValidationError' type: array title: Detail type: object title: HTTPValidationError DatasetRow: properties: row_id: type: string format: uuid4 title: Row Id index: type: integer title: Index values: items: anyOf: - type: string - type: integer - type: number - additionalProperties: anyOf: - type: string - type: integer - type: number - type: 'null' type: object - type: 'null' type: array title: Values values_dict: additionalProperties: anyOf: - type: string - type: integer - type: number - additionalProperties: anyOf: - type: string - type: integer - type: number - type: 'null' type: object - type: 'null' type: object title: Values Dict metadata: anyOf: - $ref: '#/components/schemas/DatasetRowMetadata' - type: 'null' type: object required: - row_id - index - values - values_dict - metadata title: DatasetRow ValidationError: properties: loc: items: anyOf: - type: string - type: integer type: array title: Location msg: type: string title: Message type: type: string title: Error Type type: object required: - loc - msg - type title: ValidationError DatasetRowMetadata: properties: created_in_version: type: integer title: Created In Version created_at: type: string format: date-time title: Created At created_by_user: anyOf: - $ref: '#/components/schemas/UserInfo' - type: 'null' ``` -------------------------------- ### Set Up Experiment Queries Source: https://docs.galileo.ai/getting-started/mcp/setup-galileo-mcp These queries guide you through setting up and running experiments in Galileo, including Python integration. ```text How do I set up a Galileo experiment in Python? ``` ```text Show me how to run an experiment with my RAG application ``` ```text Guide me through creating an experiment for my agentic workflow ``` -------------------------------- ### Example .env File Configuration Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim An example of the .env file content, including required and optional variables for API keys, project details, and LLM configuration. Remember to add .env to your .gitignore. ```ini # Example .env file — copy this file to .env and fill in the values. # Be sure to add the .env file to your .gitignore file. # LLM API Key (required) # For regular keys: sk-... # For project-based keys: sk-proj-... OPENAI_API_KEY=your-openai-api-key-here # OpenAI Project ID (optional for project-based keys) # OPENAI_PROJECT_ID=your-openai-project-id-here # Galileo Details (required for Galileo observability) GALILEO_API_KEY=your-galileo-api-key-here GALILEO_PROJECT=your project name here GALILEO_LOG_STREAM=my_log_stream # Provide the console url below if you are using a # custom deployment, and not using the free tier, or app.galileo.ai. # This will look something like “console.galileo.yourcompany.com”. # GALILEO_CONSOLE_URL=your-galileo-console-url # Optional LLM configuration LLM_MODEL=gpt-4 LLM_TEMPERATURE=0.7 # Optional agent configuration VERBOSITY=low # Options: none, low, high ENVIRONMENT=development ENABLE_LOGGING=true ENABLE_TOOL_SELECTION=true ``` -------------------------------- ### Basic OpenAI Responses API Call Source: https://docs.galileo.ai/sdk-api/third-party-integrations/openai/openai Demonstrates a simple, single-turn interaction with the OpenAI Responses API to get a text response. Ensure the galileo.openai library is installed. ```Python from galileo.openai import openai client = openai.OpenAI() response = client.responses.create( model="gpt-4o", input="What is the capital of France?" ) print(response.output_text) ``` -------------------------------- ### Configure Environment Variables Source: https://docs.galileo.ai/cookbooks/use-cases/multi-agent-langgraph/multi-agent-langgraph Set up your .env file by copying from .env.example and adding your OpenAI and Pinecone API keys. ```ini # AI services OPENAI_API_KEY= PINECONE_API_KEY= ``` -------------------------------- ### Full Python Example with Manual Logging Source: https://docs.galileo.ai/how-to-guides/basics/manual-span-creation/manual-span-creation A complete Python script demonstrating manual logger instantiation, trace creation, API call, conclusion, and flushing. ```python import os import asyncio import openai from dotenv import load_dotenv load_dotenv() client = openai.AsyncOpenAI(api_key=os.environ.get("OPENAI_API_KEY")) async def prompt_open_ai(prompt: str) -> str: response = await client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], ) return response.choices[0].message.content.strip() async def main(): # Create a logger instance logger = GalileoLogger() # Start a new trace logger.start_trace("Newton's First Law Trace") prompt = "Explain the following topic succinctly: Newton's First Law" response = await prompt_open_ai(prompt) print(response) logger.conclude(output=response) logger.flush() ``` -------------------------------- ### Get an existing dataset by name and delete it Source: https://docs.galileo.ai/sdk-api/python/reference/dataset This example demonstrates how to retrieve an existing dataset by its name and then proceed to delete it. Ensure the dataset name is correct and the dataset exists. ```python dataset = Dataset.get(name="my-dataset") dataset.delete() ``` -------------------------------- ### Get Dataset Content Source: https://docs.galileo.ai/sdk-api/python/reference/datasets Retrieves the content of a dataset, optionally starting from a specific token and with a defined limit. This method also updates the local dataset instance with the fetched content. ```python def get_content(self, starting_token: int=0, limit: int=MAX_DATASET_ROWS) -> None | DatasetContent\ ``` -------------------------------- ### Get Tracing Headers Source: https://docs.galileo.ai/sdk-api/python/reference/logger/logger Retrieves headers necessary for distributed tracing. These headers can be passed to downstream services to maintain trace continuity. Ensure the logger is in distributed mode and a trace has been started before calling this function. ```python logger = GalileoLogger(mode="distributed") logger.start_trace(input="question") headers = logger.get_tracing_headers() # headers = { # "X-Galileo-Trace-ID": "...", # "X-Galileo-Parent-ID": "...", # trace ID as parent # } logger.add_workflow_span(input="workflow", name="orchestrator") headers = logger.get_tracing_headers() # headers = { # "X-Galileo-Trace-ID": "...", # "X-Galileo-Parent-ID": "...", # workflow span ID as parent # } # Pass headers to HTTP request response = httpx.post(url, headers=headers) ``` -------------------------------- ### Install Luna Studio SDK with Azure OpenAI and Azure ML Deployment Extras Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the SDK with extras for data generation, training, Azure OpenAI LLM integration, and Azure Machine Learning deployment. ```bash # Example: Azure ML pip install "galileo-luna-ft[data-generation,training,llm-azure-openai,deploy-azureml]" ``` -------------------------------- ### Annotate Experiments with Tags and Metadata Source: https://docs.galileo.ai/references/faqs/faqs Use tags and metadata fields to attach filterable labels to your Traces and Spans for organization and logic. This example shows initialization and starting a trace with custom tags and metadata. ```python ## Initialize GalileoLogger logger = GalileoLogger(project="Science Exploration", log_stream="laws-of-science") prompt = f"Explain the following topic succinctly: Newton's First Law" ## Define tags and metadata tags = ["newton", "test", "new-version", "JSON"] metadata = {"experimentNumber": "1", "promptVersion": "0.0.1", "field": "physics"} ## Initialize a new trace and start listening for logs to add to it trace = logger.start_trace( input=prompt, tags=tags, metadata=metadata) ``` -------------------------------- ### Create Prompt Template Queries Source: https://docs.galileo.ai/getting-started/mcp/setup-galileo-mcp Use these examples to create and configure reusable prompt templates for different AI assistant roles. ```text Create a prompt template called "Friendly Assistant" for customer support responses ``` ```text Make a prompt template for summarizing technical documentation with lower temperature ``` ```text Set up a chat template for a code review assistant ``` -------------------------------- ### Full Agent-to-Agent Example Source: https://docs.galileo.ai/sdk-api/third-party-integrations/a2a This snippet demonstrates a complete agent-to-agent interaction. It sets up a researcher agent as a server and then runs an orchestrator agent that communicates with it to plan a trip. Requires setup of both agents and their respective components. ```python CARD = AgentCard( name="researcher", description="Travel researcher with tool use", url="http://localhost:9867", version="1.0.0", capabilities=AgentCapabilities(streaming=True), default_input_modes=["text/plain"], default_output_modes=["text/plain"], skills=[AgentSkill(id="qa", name="Q&A", description="Answer questions", tags=[])], ) # --- Agent A: orchestrator (LangGraph) --- class OrchestratorState(TypedDict): user_query: str research_query: str response: str plan: str def build_orchestrator(client): async def plan(state: OrchestratorState) -> dict: prompt = ( "Formulate a travel research question." " Reply with ONLY the question." ) result = await create_agent( llm, system_prompt=prompt, ).ainvoke({"messages": [("user", state["user_query"])]}) return {"research_query": result["messages"][-1].content} async def delegate(state: OrchestratorState) -> dict: msg = Message( message_id=str(uuid.uuid4()), role=Role.user, parts=[TextPart(text=state["research_query"])], context_id="session-1", ) async for event in client.send_message(msg): if isinstance(event, tuple): task = event[0] is_done = ( task.status and task.status.state == TaskState.completed and task.status.message ) if is_done: text = getattr( task.status.message.parts[0].root, "text", "", ) return {"response": text} return {"response": ""} async def synthesize(state: OrchestratorState) -> dict: prompt = "Create a brief 3-day itinerary from the research." user_msg = ( f"Research:\n{state['response']}" "\n\nCreate itinerary." ) result = await create_agent( llm, system_prompt=prompt, ).ainvoke({"messages": [("user", user_msg)]}) return {"plan": result["messages"][-1].content} graph = StateGraph(OrchestratorState) graph.add_node("plan", plan) graph.add_node("delegate", delegate) graph.add_node("synthesize", synthesize) graph.add_edge(START, "plan") graph.add_edge("plan", "delegate") graph.add_edge("delegate", "synthesize") graph.add_edge("synthesize", END) return graph.compile() # --- Run both agents --- async def main(): # Start Agent B app = Starlette() A2AStarletteApplication( agent_card=CARD, http_handler=DefaultRequestHandler( agent_executor=ResearcherExecutor(), task_store=InMemoryTaskStore(), queue_manager=InMemoryQueueManager(), ), ).add_routes_to_app(app) server = uvicorn.Server(uvicorn.Config(app, port=9867, log_level="warning")) server_task = asyncio.create_task(server.serve()) await asyncio.sleep(1) # Run Agent A client = ClientFactory( config=ClientConfig( streaming=True, httpx_client=httpx.AsyncClient( timeout=httpx.Timeout(120), ), ), ).create(CARD) result = await build_orchestrator(client).ainvoke({ "user_query": "Plan a 3-day trip to Paris", "research_query": "", "response": "", "plan": "", }) print(result["plan"]) server.should_exit = True await server_task provider.shutdown() asyncio.run(main()) ``` -------------------------------- ### Get lc_namespace Signature Source: https://docs.galileo.ai/sdk-api/typescript/reference/README/classes/GalileoCallback Retrieves the module path as a tuple of strings, indicating the class's location within the library. For example, ["langchain_core", "callbacks", "string"]. ```typescript get lc_namespace(): ["langchain_core", "callbacks", string]; ``` -------------------------------- ### Full Example: Microsoft Agent Framework Tool Calling with Galileo Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/microsoft-agent-framework A complete example demonstrating tool calling with the Microsoft Agent Framework, integrated with Galileo for observability. Ensure your .env file contains necessary API keys and project details. ```python from random import randint from typing import Annotated from agent_framework import openai, tool from agent_framework.observability import enable_instrumentation from galileo.otel import GalileoSpanProcessor, add_galileo_span_processor from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from pydantic import Field # Set up the OTel tracer provider with the Galileo span processor tracer_provider = TracerProvider() galileo_processor = GalileoSpanProcessor() add_galileo_span_processor(tracer_provider, galileo_processor) trace.set_tracer_provider(tracer_provider) # Enable the Microsoft Agent Framework's built-in OTel instrumentation. # Set enable_sensitive_data=True to send LLM inputs and outputs to Galileo. # If set to False, only span metadata (timing, token counts, etc.) will be sent. enable_instrumentation(enable_sensitive_data=True) @tool(approval_mode="never_require") def get_weather( location: Annotated[ str, Field(description="The location to get the weather for.") ], ) -> str: """Get the weather for a given location.""" conditions = ["sunny", "cloudy", "rainy", "stormy"] temp = randint(10, 30) condition = conditions[randint(0, 3)] return f"The weather in {location} is {condition}, {temp}C." client = openai.OpenAIChatClient(model_id="gpt-4.1-mini") agent = client.as_agent( name="WeatherAgent", instructions="You are a helpful weather agent. " "Use the get_weather tool to answer questions.", tools=[get_weather], ) async def main(): result = await agent.run("What's the weather like in Seattle?") print(result) if __name__ == "__main__": import asyncio asyncio.run(main()) ``` -------------------------------- ### Annotate Experiments with Tags and Metadata (TypeScript) Source: https://docs.galileo.ai/references/faqs/faqs Use tags and metadata fields to attach filterable labels to your Traces and Spans for organization and logic. This example shows initialization and starting a trace with custom tags and metadata. ```typescript // Initialize GalileoLogger const logger = new GalileoLogger({ projectName: "Science Exploration", logStreamName: "laws-of-science" }); const prompt = "Explain the following topic succinctly: Newton's First Law"; // Define tags and metadata const tags = ["newton", "test", "new-version", "JSON"]; const metadata = { experimentNumber: "1", promptVersion: "0.0.1", field: "physics" }; // Initialize a new Trace and start listening for logs to add to it const trace = logger.startTrace({ input: prompt, tags, metadata, }); ``` -------------------------------- ### Set up environment variables (.env file) Source: https://docs.galileo.ai/getting-started/quickstart Configure your Galileo API key and OpenAI API Key in the .env file. The GALILEO_CONSOLE_URL can be provided if not using app.galileo.ai. ```ini GALILEO_API_KEY="your-galileo-api-key" OPENAI_API_KEY="your-openai-api-key" # Provide the console url below if you are not using app.galileo.ai # GALILEO_CONSOLE_URL="your-galileo-console-url" ``` -------------------------------- ### Full A2A Agent Integration Example Source: https://docs.galileo.ai/sdk-api/third-party-integrations/a2a A comprehensive Python script demonstrating two LangGraph agents communicating via A2A. It includes Galileo tracing setup, agent definitions, and the A2A server/client configuration. ```python import asyncio import uuid import httpx import uvicorn from a2a.client import ClientConfig, ClientFactory from a2a.server.agent_execution import AgentExecutor, RequestContext from a2a.server.apps.jsonrpc.starlette_app import A2AStarletteApplication from a2a.server.events import EventQueue, InMemoryQueueManager from a2a.server.request_handlers.default_request_handler import DefaultRequestHandler from a2a.server.tasks import InMemoryTaskStore from a2a.types import ( AgentCapabilities, AgentCard, AgentSkill, Message, Role, TaskState, TaskStatus, TaskStatusUpdateEvent, TextPart, ) from dotenv import load_dotenv from galileo.otel import GalileoSpanProcessor, add_galileo_span_processor from galileo_a2a import A2AInstrumentor from langchain.agents import create_agent from langchain_core.tools import tool from langchain_openai import ChatOpenAI from langgraph.graph import END, START, StateGraph from opentelemetry.instrumentation.langchain import LangchainInstrumentor from opentelemetry.sdk.trace import TracerProvider from starlette.applications import Starlette from typing_extensions import TypedDict # Load GALILEO_API_KEY, GALILEO_CONSOLE_URL, OPENAI_API_KEY, etc. from .env # into the process environment before constructing GalileoSpanProcessor. load_dotenv() # --- Galileo tracing setup --- provider = TracerProvider() add_galileo_span_processor(provider, GalileoSpanProcessor()) A2AInstrumentor().instrument(tracer_provider=provider, agent_name="orchestrator") LangchainInstrumentor().instrument(tracer_provider=provider) llm = ChatOpenAI(model="gpt-4o-mini") # --- Agent B: researcher (served over A2A) --- @tool def search_kb(query: str) -> str: """Search the travel knowledge base.""" if "paris" in query.lower(): return "Eiffel Tower 330m, Louvre 9.6M visitors/yr, 20 arrondissements." return f"No results for: {query}" researcher = create_agent( llm, [search_kb], system_prompt="Use search_kb to find facts, then summarize for a traveler.", ) class ResearcherExecutor(AgentExecutor): async def execute(self, ctx: RequestContext, queue: EventQueue) -> None: result = await researcher.ainvoke({"messages": [("user", ctx.get_user_input())]}) await queue.enqueue_event(TaskStatusUpdateEvent( task_id=ctx.task_id, context_id=ctx.context_id, final=True, status=TaskStatus( state=TaskState.completed, message=Message( message_id=str(uuid.uuid4()), role=Role.agent, parts=[TextPart(text=result["messages"][-1].content or "")], ), ), )) async def cancel(self, ctx: RequestContext, queue: EventQueue) -> None: await queue.enqueue_event(TaskStatusUpdateEvent( task_id=ctx.task_id, context_id=ctx.context_id, final=True, status=TaskStatus(state=TaskState.canceled), )) ``` -------------------------------- ### Get Metric Aggregates with Polling Source: https://docs.galileo.ai/sdk-api/python/reference/experiment Retrieves aggregate statistics for a specific metric. The example demonstrates polling until the metric is computed and then asserting its average value. Metrics can be identified by GalileoMetrics enum, scorer UUID, human-readable label, or legacy alias. ```python from galileo.schema.metrics import GalileoMetrics while experiment.get_metric_aggregate(GalileoMetrics.correctness) is None: time.sleep(5) experiment.refresh() agg = experiment.get_metric_aggregate(GalileoMetrics.correctness) assert agg.avg >= 0.95 ``` -------------------------------- ### Install Project Dependencies Source: https://docs.galileo.ai/cookbooks/use-cases/multi-agent-langgraph/multi-agent-langgraph Install project dependencies using uv. Ensure you have a virtual environment set up first. ```bash uv venv .venv source .venv/bin/activate uv sync --dev ``` -------------------------------- ### Example Terminal Output with Tool Use Source: https://docs.galileo.ai/how-to-guides/basics/log-mcp-server-calls/log-mcp-server-calls This output shows the initial connection message listing available tools, followed by a user query, the LLM's tool use request, and the beginning of the tool's response. It demonstrates the flow when the chatbot interacts with the MCP server. ```output Connected to server with tools: ['integrate_galileo_with_langchain', 'integrate_galileo_with_openai', 'get_logstream_insights', 'validate_dataset', 'create_galileo_dataset', 'create_prompt_template', 'setup_galileo_experiment', 'search_docs'] Query: How do I use the GalileoLogger? I'll search the Galileo documentation to find information about how to use the GalileoLogger. [Calling tool search_docs with args {'query': 'GalileoLogger usage how to use'}] # Using the GalileoLogger The **GalileoLogger** class provides granular control over logging in Galileo. Here's how to use it: ... ``` -------------------------------- ### get_request_logger Example with Trace ID Check Source: https://docs.galileo.ai/sdk-api/python/reference/middleware/tracing Demonstrates how to use get_request_logger in a Starlette handler, checking for existing trace context to either add a workflow span or start a new trace. It also includes concluding the trace and flushing/terminating the logger. ```python @app.post("/retrieve") async def retrieve_endpoint(query: str): # Get logger with trace context from upstream service logger = get_request_logger() # If trace context exists, this creates a workflow span # Otherwise, it starts a new trace if logger.trace_id: logger.add_workflow_span(input=query, name="retrieval_service") else: logger.start_trace(input=query, name="retrieval_service") results = retrieve(query, logger) logger.conclude(output=str(results)) logger.flush() logger.terminate() return {"results": results} ``` -------------------------------- ### Install Luna Studio SDK with Azure OpenAI LLM Provider Extra Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the SDK including extras for data generation, training, and integration with Azure OpenAI for LLM operations. ```bash # Example: Azure OpenAI pip install "galileo-luna-ft[data-generation,training,llm-azure-openai]" ``` -------------------------------- ### Handle Logging Sensitive Data (TypeScript) Source: https://docs.galileo.ai/references/faqs/faqs Mask, anonymize, or exclude sensitive data like PII before logging. Use annotations to mark sensitive content without logging it directly. This example shows starting a trace with redacted input and specific tags/metadata. ```typescript const trace = logger.startTrace({ input: "REDACTED", tags: ['PII_REDACTED'], metadata: {"pii_redacted": "True"} }); ``` -------------------------------- ### Handle Logging Sensitive Data (Python) Source: https://docs.galileo.ai/references/faqs/faqs Mask, anonymize, or exclude sensitive data like PII before logging. Use annotations to mark sensitive content without logging it directly. This example shows starting a trace with redacted input and specific tags/metadata. ```python trace = logger.start_trace( input="REDACTED", tags=['PII_REDACTED'], metadata={"pii_redacted": "True"}) ``` -------------------------------- ### Run Experiment with Prompt (Python Beta) Source: https://docs.galileo.ai/sdk-api/experiments/prompts Create an `Experiment` object, providing the dataset, prompt, metrics, and project name. The `create()` method automatically runs the experiment. ```python from galileo import Dataset, Experiment, Metric, Prompt # Get an existing dataset dataset = Dataset.get(name="countries") if dataset is None: raise ValueError("Dataset 'countries' not found") # Get an existing prompt prompt = Prompt.get(name="geography-prompt") if prompt is None: raise ValueError("Prompt 'geography-prompt' not found") # Create and run the experiment in one step # (create() triggers the run automatically) experiment = Experiment( name="geography-experiment", dataset=dataset, prompt=prompt, metrics=[Metric.metrics.completeness], project_name="my-project", ) experiment.create() ``` -------------------------------- ### Get Tracing Headers for Decorator Usage Source: https://docs.galileo.ai/sdk-api/python/reference/tracing Use this function to retrieve tracing headers from the singleton logger context when using decorators. These headers are essential for propagating trace context to downstream services. Ensure you are in distributed mode and a trace has been started, otherwise a GalileoLoggerException will be raised. ```python from galileo import log, get_tracing_headers import httpx @log() async def orchestrator(): # Get headers to pass to downstream service headers = get_tracing_headers() # Call downstream service with trace context async with httpx.AsyncClient() as client: response = await client.post( "http://service:8000/process", headers=headers, json={"data": "..."} ) ```