### Full TypeScript Example for 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, interaction with OpenAI API, trace conclusion with output, 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(); ``` -------------------------------- ### Full Agent Setup with OTel and Galileo Source: https://docs.galileo.ai/how-to-guides/experiments/otel-experiment/otel-experiment This comprehensive example demonstrates setting up OpenTelemetry with Galileo, enabling framework instrumentation, defining tools, and configuring an OpenAI agent. It includes the necessary imports and agent logic for a complete agent implementation. ```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 Luna Studio SDK with Extras Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the SDK with data generation and training extras. Use this command for a standard installation. ```bash pip install "galileo-luna-ft[data-generation,training]" ``` -------------------------------- ### Full RAG Agent Execution Example Source: https://docs.galileo.ai/cookbooks/use-cases/rag-elastic-langchain-integration Demonstrates the complete setup and execution of the RAG agent, including Elasticsearch initialization, agent compilation, and a Q&A session with follow-up questions. This script shows how to integrate all components. ```Python # Step 1: Set up Elasticsearch index and data document_store = setup_elasticsearch() # Step 2: Compile the agent and its workflow rag_agent_graph = setup_agent_and_graph(document_store) # Step 3: Start a Q&A session print("\n--- Starting Q&A Session ---") session_id = f"session-{int(time.time())}" # Ask the first question question1 = "How many vacation days do new hires get?" print(f"\n❓ Question: {question1}") answer1 = ask_question(rag_agent_graph, question1, session_id) print(f"✅ Answer: {answer1}") # Ask a follow-up question question2 = "What about health insurance?" print(f"\n❓ Question: {question2}") answer2 = ask_question(rag_agent_graph, question2, session_id) print(f"✅ Answer: {answer2}") ``` -------------------------------- ### Run Distributed Tracing Example Source: https://docs.galileo.ai/sdk-api/logging/distributed-tracing-otel Install dependencies, run two agent applications on different ports, and send a request to observe distributed tracing in action. Use `jq` to pretty-print the JSON output. ```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 ``` -------------------------------- ### Full Code Sample for Galileo Session Logging Source: https://docs.galileo.ai/concepts/logging/sessions/using-sessions This comprehensive example shows how to set up Galileo logging, create a simple agent, start a session, and invoke the agent with prompts, ensuring all traces are captured within the session. ```Python from time import time from dotenv import load_dotenv # Galileo dependencies from galileo import GalileoLogger from galileo.handlers.langchain import GalileoCallback # LangChain and LangGraph dependencies from langchain.agents import create_agent from langchain_core.runnables.config import RunnableConfig # Load `.env` variables load_dotenv() # Create a simple assistant for our test (or import one). You can also provide # your agent with tools: the session will log their usage simple_agent = create_agent( name="simple_agent", model="openai:o3-mini", # you can choose any OpenAI model here system_prompt="You are a friendly assistant that answers the user's questions", tools=[], # (OPTIONAL) provide tools to your agent ) # Create a GalileoLogger instance logger = GalileoLogger() def main(): """Main application logic""" # start a logging session external_id = f"custom_id-{int(time())}" logger.start_session(name="Logger Session Tutorial", external_id=external_id) # Here's what we will ask the LLM: prompts = [ "Hello! How many minutes are in a year?", "Hello! How far is an Astronomical Unit in kilometers?", ] # Create a LangChain Runnable config object with a LangGraph callback handler: # We will supply the logger instance to ensure that it generates traces in the # correct session agent_config = RunnableConfig(callbacks=[GalileoCallback(galileo_logger=logger)]) for prompt in prompts: # Invoke the LLM with our question: response = simple_agent.invoke( input={"messages": [{"role": "user", "content": prompt}]} config=agent_config, # pass the RunnableConfig here ) # Print out the LLM's response to confirm that this code block ran: print("Model response:", response["messages"][-1].content.strip()) if __name__ == "__main__": main() ``` ```TypeScript import { configDotenv } from "dotenv"; // Galileo dependencies import { GalileoCallback, GalileoLogger } from "galileo"; // LangChain and LangGraph dependencies import { createReactAgent } from "@langchain/langgraph/prebuilt"; import { RunnableConfig } from "@langchain/core/runnables"; import { ChatOpenAI } from "@langchain/openai"; // Load environment variables configDotenv(); // Create a simple assistant for our test (or import one). You can also provide // your agent with tools: the session will log their usage const simpleAgent = createReactAgent({ name: "simpleAgent", llm: new ChatOpenAI({ model: "o3-mini" }), prompt: "You are a friendly assistant that answers the user's questions", tools: [] // (OPTIONAL) provide tools to your agent }); // Create a GalileoLogger instance for our session const logger = new GalileoLogger(); /** Main application logic */ async function main() { // Start a logging session const externalId = `custom_id-${Math.round(Date.now() / 1000)}`; await logger.startSession({ name: "Logger Session Tutorial", externalId }); // Here's what we will ask the LLM: const prompts = [ "Hello! How many minutes are in a year?", "Hello! How far is an Astronomical Unit in kilometers?" ]; // Create a LangChain Runnable config object with a LangGraph callback handler. // We will supply the logger instance to ensure that it generates traces in the // correct session const agentConfig: RunnableConfig = { callbacks: [new GalileoCallback(logger)] }; for (const prompt of prompts) { // Invoke the LLM with our question: const result = await simpleAgent.invoke( { messages: [{ role: "user", content: prompt }] }, agentConfig // pass the RunnableConfig here ); // Print out the LLM's response to confirm that this code block ran: console.log("LLM Reply:", result.messages.at(-1)?.content); } } main(); ``` -------------------------------- ### Full Python Example for Manual Logging Source: https://docs.galileo.ai/how-to-guides/basics/manual-span-creation/manual-span-creation A complete Python script demonstrating manual creation of a logger, starting a trace, calling an external API, concluding the trace with the response, and flushing the logs. ```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() ``` -------------------------------- ### Install Dependencies with uv Source: https://docs.galileo.ai/cookbooks/use-cases/agent-weather-vibes-app Install project dependencies using uv by referencing 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 OpenTelemetry Packages Source: https://docs.galileo.ai/sdk-api/third-party-integrations/a2a Install the core OpenTelemetry packages and the OTLP exporter for sending traces to Galileo. ```bash pip install opentelemetry-api opentelemetry-sdk \ opentelemetry-exporter-otlp ``` -------------------------------- ### Install Galileo Python SDK Source: https://docs.galileo.ai/sdk-api/python/sdk-reference Install the Galileo Python SDK using pip, uv, or poetry. ```bash pip install galileo ``` ```bash uv pip install galileo ``` ```bash poetry add galileo ``` -------------------------------- ### Install Dependencies with pip Source: https://docs.galileo.ai/cookbooks/use-cases/agent-weather-vibes-app Install project dependencies using pip by referencing the requirements.txt file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Galileo with uv Source: https://docs.galileo.ai/how-to-guides/third-party-integrations/add-galileo-to-crewai/add-galileo-to-crewai Install the Galileo package using uv. Ensure you are within a virtual environment. ```bash uv pip install galileo ``` -------------------------------- ### Get Integration Help from 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 Repository and Navigate Source: https://docs.galileo.ai/cookbooks/use-cases/agent-langchain Clone the SDK examples repository and navigate to the LangChain agent directory. This is the first step to setting up the project. ```bash git clone https://github.com/rungalileo/sdk-examples.git cd sdk-examples/python/agent/langchain-agent ``` -------------------------------- ### Start OpenTelemetry Processor (GalileoSpanProcessor) Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/vercel-ai Initialize and start the NodeSDK with GalileoSpanProcessor for automatic OTLP configuration. 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(); ``` -------------------------------- ### Clone Repository and Navigate Source: https://docs.galileo.ai/cookbooks/features/integrations/langgraph-otel-cookbook Clone the SDK examples repository and navigate into the LangGraph-OTel directory. This sets up the project structure for the tutorial. ```bash git clone https://github.com/rungalileo/sdk-examples cd sdk-examples/python/agent/langgraph-otel ``` -------------------------------- ### Python Dataset Get Content Example Source: https://docs.galileo.ai/sdk-api/python/reference/dataset Retrieves the content of an existing dataset. ```python dataset = Dataset.get(name="my-dataset") content = dataset.get_content() ``` -------------------------------- ### Set Up Virtual Environment and Install Dependencies (Windows) Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Create a virtual environment using uv and install project dependencies from requirements.txt. This isolates project dependencies. ```bash uv venv source .venv\Scripts\activate uv pip install -r requirements.txt ``` -------------------------------- ### Responses API Basic Example Source: https://docs.galileo.ai/sdk-api/third-party-integrations/openai/openai A simple example demonstrating how to make a basic request to the OpenAI Responses API using the Galileo SDK to get a text response. ```APIDOC ## Responses API basic example This example shows a basic interaction with the Responses API. ### Method ```python client.responses.create ``` ### Parameters - **model** (string) - Required - The model to use for generation (e.g., "gpt-4o"). - **input** (string) - Required - The user's input prompt. ### Request Example ```python from galileo.openai import openai client = openai.OpenAI() response = client.responses.create( model="gpt-4o", input="What is the capital of France?" ) ``` ### Response - **output_text** (string) - The generated text output from the model. ``` -------------------------------- ### Clone the SDK Examples Repository Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Clone the repository containing the startup simulator project. This command downloads all project files to your local machine. ```bash git clone https://github.com/rungalileo/sdk-examples ``` -------------------------------- ### 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 Create a virtual environment using uv and install project dependencies from requirements.txt. This isolates project dependencies. ```bash uv venv source .venv/bin/activate uv pip install -r requirements.txt ``` -------------------------------- ### Python Dataset Get Versions Example Source: https://docs.galileo.ai/sdk-api/python/reference/dataset Retrieves a list of versions for a dataset and iterates through them to print version index and row count. ```python dataset = Dataset.get(name="my-dataset") versions = dataset.get_versions() for v in versions.versions: print(v.version_index, v.num_rows) ``` -------------------------------- ### Get Paginated Experiments Source: https://docs.galileo.ai/sdk-api/typescript/reference Retrieves experiments with pagination options. Supports including counts, limiting results, and starting from a specific token. ```typescript getExperimentsPaginated(options?: object): Promise; ``` -------------------------------- ### Example .env Configuration File Source: https://docs.galileo.ai/cookbooks/use-cases/custom-metric-startup-sim/custom-metric-startup-sim Configure your environment variables by copying the .example.env file to .env and filling in your API keys and project details. Ensure .env is added 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 ENVIRONMENT=development ENABLE_LOGGING=true ENABLE_TOOL_SELECTION=true ``` -------------------------------- ### OpenAI Responses API Basic Example Source: https://docs.galileo.ai/sdk-api/third-party-integrations/openai/openai Demonstrates a basic interaction with the OpenAI Responses API to get a text response. Ensure the OpenAI client is initialized. ```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) ``` -------------------------------- ### 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 ``` -------------------------------- ### Get Configured Azure OpenAI Integration Source: https://docs.galileo.ai/sdk-api/python/reference/integration Retrieve the configured Azure OpenAI integration provider. Use this to verify the setup and obtain the integration's ID. ```python azure = Integration.azure if azure: print(f"Azure integration: {azure.id}") ``` -------------------------------- ### Install SDK with Azure ML Deployment Extra Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the SDK with data generation, training, Azure OpenAI LLM provider, and Azure ML deployment extras. Use this for deploying to Azure ML. ```bash # Example: Azure ML pip install "galileo-luna-ft[data-generation,training,llm-azure-openai,deploy-azureml]" ``` -------------------------------- ### Get Tracing Headers Source: https://docs.galileo.ai/sdk-api/python/reference/logger/logger Retrieves headers necessary for distributed tracing. Use this to pass trace context to downstream services. Ensure the logger is in distributed mode and a trace has been started. ```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 SDK with Azure OpenAI Extra Source: https://docs.galileo.ai/luna-studio/sdk/installation Install the SDK with data generation, training, and Azure OpenAI LLM provider extras. Choose this if you use Azure OpenAI for generation or labeling. ```bash # Example: Azure OpenAI pip install "galileo-luna-ft[data-generation,training,llm-azure-openai]" ``` -------------------------------- ### Get Dataset Content Source: https://docs.galileo.ai/sdk-api/python/reference/datasets Retrieve the content of a dataset. This method also updates the local dataset instance with the latest content. You can specify a starting token and a limit for the number of rows to fetch. ```python def get_content(self, starting_token: int=0, limit: int=MAX_DATASET_ROWS) -> None | DatasetContent ``` -------------------------------- ### Start Trace with Tags and Metadata (Python) Source: https://docs.galileo.ai/sdk-api/logging/tags-and-metadata Initializes a new trace and begins listening for logs, attaching the defined tags and metadata to it. ```Python # Initialize a new Trace and start listening for logs to add to it trace = logger.start_trace( input=prompt, tags=tags, metadata=metadata ) ``` -------------------------------- ### Configure Environment Variables Source: https://docs.galileo.ai/cookbooks/use-cases/multi-agent-langgraph Set up your API keys for AI services by copying the .env.example file to .env and filling in your OpenAI and Pinecone API keys. ```bash # AI services OPENAI_API_KEY= PINECONE_API_KEY= ``` -------------------------------- ### Example Columns Source: https://docs.galileo.ai/api-reference/experiment/experiments-available-columns Illustrates sample column configurations available in the system. ```APIDOC ## Example Columns ### Experiment Group Id - **label**: Experiment Group Id - **multi_valued**: false - **sortable**: true ### Experiment Group Name - **applicable_types**: [] - **category**: standard - **data_type**: text - **filterable**: true - **group_label**: Standard - **id**: experiment_group_name - **is_empty**: false - **is_optional**: true - **multi_valued**: false - **sortable**: true ### Experiment Group Is System - **applicable_types**: [] - **category**: standard - **data_type**: boolean - **filterable**: true - **group_label**: Standard - **id**: experiment_group_is_system - **is_empty**: false - **is_optional**: true - **multi_valued**: false - **sortable**: true ### Average Cost - **applicable_types**: [] - **category**: metric - **data_type**: floating_point - **filterable**: true - **id**: metrics/average_cost - **is_empty**: false - **is_optional**: false - **label**: Average Cost - **multi_valued**: false - **sortable**: true ### Average Bleu - **applicable_types**: [] - **category**: metric - **data_type**: floating_point - **filterable**: true - **id**: metrics/average_bleu - **is_empty**: false - **is_optional**: false - **label**: Average Bleu - **multi_valued**: false - **sortable**: true ### Total Responses - **applicable_types**: [] - **category**: metric - **data_type**: integer - **filterable**: true - **id**: metrics/total_responses - **is_empty**: false - **is_optional**: false - **label**: Total Responses - **multi_valued**: false - **sortable**: true ``` -------------------------------- ### 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 logged Traces and Spans for organization and logic. This example shows initialization and trace start with custom annotations. ```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) ``` -------------------------------- ### 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 logged Traces and Spans for organization and logic. This example shows initialization and trace start with custom annotations. ```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, }); ``` -------------------------------- ### Copy Environment File Source: https://docs.galileo.ai/cookbooks/features/integrations/langgraph-otel-cookbook Copy the example environment file to create your own .env file. This file will store your API keys and project configurations. ```bash cp .env.example .env ``` -------------------------------- ### Get Logstream Insights Token Usages Source: https://docs.galileo.ai/api-reference/logstream-insights/get-logstream-insights-token-usages Fetches token usage data for a specific log stream within a project. You can control the results using parameters like starting token, limit, filters, and sorting. ```APIDOC ## POST /v2/projects/{project_id}/log_streams/{log_stream_id}/logstream_insights/token_usage ### Description Retrieves token usage statistics for a given log stream. This endpoint supports pagination and allows for detailed filtering and sorting of the results. ### Method POST ### Endpoint /v2/projects/{project_id}/log_streams/{log_stream_id}/logstream_insights/token_usage ### Parameters #### Path Parameters - **project_id** (string) - Required - The unique identifier for the project. - **log_stream_id** (string) - Required - The unique identifier for the log stream. #### Request Body - **starting_token** (integer) - Optional - The token to start pagination from. Defaults to 0. - **limit** (integer) - Optional - The maximum number of results to return. Defaults to 100. - **filters** (array) - Optional - An array of filter objects to narrow down the results. Supported filters include `created_at` and `updated_at`. - **name** (string) - Required - The name of the field to filter on (e.g., `created_at`). - **operator** (string) - Required - The comparison operator (e.g., `eq`, `ne`, `gt`, `gte`, `lt`, `lte`). - **value** (string) - Required - The value to compare against, in `date-time` format. - **sort** (object) - Optional - An object to specify the sorting order. Defaults to sorting by `created_at` in descending order. - **name** (string) - Required - The field to sort by (e.g., `created_at`). - **ascending** (boolean) - Required - `true` for ascending, `false` for descending. - **sort_type** (string) - Required - The type of sort, typically `column`. ### Request Example ```json { "starting_token": 0, "limit": 100, "filters": [ { "name": "created_at", "operator": "gte", "value": "2023-10-27T10:00:00Z" } ], "sort": { "name": "created_at", "ascending": false, "sort_type": "column" } } ``` ### Response #### Success Response (200) - **starting_token** (integer) - The token for the current page of results. - **limit** (integer) - The limit applied to the results. - **paginated** (boolean) - Indicates if the results are paginated. - **next_starting_token** (integer | null) - The token for the next page of results, or null if there are no more pages. - **token_usages** (array) - An array of token usage objects. - Each object in the array represents token usage details for a log stream insight. #### Response Example ```json { "starting_token": 0, "limit": 100, "paginated": true, "next_starting_token": 100, "token_usages": [ { "id": "some-usage-id", "created_at": "2023-10-27T10:30:00Z", "updated_at": "2023-10-27T10:30:00Z", "prompt_tokens": 150, "completion_tokens": 50, "total_tokens": 200 } ] } ``` #### Error Response (422) - **detail** (array) - An array of validation error objects. - Each object contains information about a validation error, such as a location and message. #### Error Response Example ```json { "detail": [ { "loc": [ "body", "limit" ], "msg": "ensure this value is greater than or equal to 1", "type": "value_error.number.min" } ] } ``` ``` -------------------------------- ### Set Up Experiments Queries Source: https://docs.galileo.ai/getting-started/mcp/setup-galileo-mcp These queries guide you through setting up and running Galileo experiments. They cover Python integration, RAG applications, and agentic workflows. ```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 ``` -------------------------------- ### Full Example: Microsoft Agent Framework with OpenTelemetry Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/microsoft-agent-framework A complete example demonstrating tool usage and OpenTelemetry integration for logging traces to Galileo. Ensure your environment variables for API keys and project details are set. ```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()) ``` -------------------------------- ### Complete Application Code Setup Source: https://docs.galileo.ai/how-to-guides/third-party-integrations/openai-agent-integration This code provides the full setup for the 'Homework Assistant' AI agent application, including necessary imports, agent definitions, and the main execution logic. ```python from galileo.handlers.openai_agents import GalileoTracingProcessor from agents import ( set_trace_processors, Agent, GuardrailFunctionOutput, InputGuardrail, Runner ) from pydantic import BaseModel import asyncio from dotenv import load_dotenv load_dotenv() # Create a class with BaseModel to validate output types class HomeworkOutput(BaseModel): is_homework: bool reasoning: str # Create math tutor agent to answer math questions math_tutor_agent = Agent( name="Math Tutor", handoff_description="Specialist agent for math questions", instructions=""" You provide help with math problems. Explain your reasoning at each step and include examples """, ) ``` -------------------------------- ### Initialize Galileo Context (Python) Source: https://docs.galileo.ai/sdk-api/logging/tags-and-metadata Sets up the Galileo project and log stream. These are created if they don't already exist. ```Python from datetime import datetime from galileo import galileo_context from galileo import GalileoLogger from galileo.config import GalileoPythonConfig import openai from dotenv import load_dotenv # Load environment variables from the .env file load_dotenv() # Set the project and Log stream, these are created if they don't exist. galileo_context.init(project="MyFirstTagandMetadata", log_stream="MyFirstTagandMetatdata") ``` -------------------------------- ### Handle Sensitive Data with Redacted Annotations (TypeScript) Source: https://docs.galileo.ai/references/faqs/faqs Mark sensitive content like PII using tags and metadata without logging it directly. This example shows starting a trace with 'REDACTED' input and specific PII-related annotations. ```typescript const trace = logger.startTrace({ input: "REDACTED", tags: ['PII_REDACTED'], metadata: {"pii_redacted": "True"} }); ``` -------------------------------- ### Handle Sensitive Data with Redacted Annotations (Python) Source: https://docs.galileo.ai/references/faqs/faqs Mark sensitive content like PII using tags and metadata without logging it directly. This example shows starting a trace with 'REDACTED' input and specific PII-related annotations. ```python trace = logger.start_trace( input="REDACTED", tags=['PII_REDACTED'], metadata={"pii_redacted": "True"}) ``` -------------------------------- ### Process Query with LLM and Tools Source: https://docs.galileo.ai/how-to-guides/agentic-ai/basic-example Loads tools, constructs a system prompt with instructions and examples, and makes the initial API call to the LLM for query processing. ```python def process_query(query): # Load tools tools = load_tools() console.print("[bold blue]Processing query...[/bold blue]") console.print(f"Query: {query}") # Debug: Print the tools being used console.print(f"[dim]Loaded {len(tools)} tools[/dim]") # Ask LLM to process the query with a clear plan messages = [{"role": "system", "content": """ You are an agent that processes numerical queries using these tools: 1. convert_text_to_number: Converts text numbers (like "seven") to digits (7) 2. calculate: Performs arithmetic with numerical expressions ("4 + 7") For ANY query containing arithmetic operations (+, -, *, / or plus, minus, times, divide): 1. You MUST first convert any text numbers to digits 2. You MUST then perform the calculation with the converted numbers 3. Both steps are required - never stop after just converting numbers"""}, {"role": "user", "content": """Example: "What's 4 + seven?" Required steps: 1. convert_text_to_number(text="seven") -> 7 2. calculate(expression="4 + 7") # This step is mandatory! Example: "What's three plus seven?" Required steps: 1. convert_text_to_number(text="three") -> 3 2. convert_text_to_number(text="seven") -> 7 3. calculate(expression="3 + 7") # This step is mandatory! Never stop after just converting numbers - you must calculate the result!"""}, {"role": "user", "content": f"Process this query: '{query}'" }] response = client.chat.completions.create( model="gpt-4o", messages=messages, tools=tools, ) ``` -------------------------------- ### 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. Includes Galileo tracing setup, LLM configuration, and agent definitions for both orchestrator and researcher roles. ```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), )) ``` -------------------------------- ### Full Strands Agent Example with OpenTelemetry Source: https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference/strands-agents This Python script demonstrates a complete Strands Agent setup. It configures OpenTelemetry to export traces to Galileo, defines a custom tool for letter counting, and initializes an agent with various tools to answer a multi-part message. ```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) ``` -------------------------------- ### Create and Manage Log Streams Source: https://docs.galileo.ai/sdk-api/python/reference/log_stream Demonstrates creating a new log stream, retrieving an existing one, and creating log streams via a Project instance. Also shows how to enable and refresh metrics for a log stream. ```python log_stream = LogStream(name="Production Logs", project_name="My AI Project").create() log_stream = LogStream.get(name="Production Logs", project_name="My AI Project") from galileo.project import Project project = Project.get(name="My AI Project") log_stream = project.create_log_stream(name="Production Logs") from galileo.schema.metrics import GalileoMetrics local_metrics = log_stream.enable_metrics([ GalileoMetrics.correctness, GalileoMetrics.completeness, "context_relevance" ]) log_stream.refresh() ``` -------------------------------- ### Get Tracing Headers for Downstream Services Source: https://docs.galileo.ai/sdk-api/python/reference/tracing Use this function to retrieve tracing headers from the singleton logger context. These headers are essential for propagating trace context to downstream services when using decorators. Ensure distributed tracing is enabled 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": "..."} ) ```