sample_id
stringlengths
21
196
text
stringlengths
105
936k
metadata
dict
category
stringclasses
6 values
letta-ai/letta:tests/test_provider_trace_agents.py
""" Unit tests for provider trace telemetry across agent versions and adapters. Tests verify that telemetry context is correctly passed through: - Tool generation endpoint - LettaAgent (v1), LettaAgentV2, LettaAgentV3 - Streaming and non-streaming paths - Different stream adapters """ import uuid from unittest.mock i...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_provider_trace_agents.py", "license": "Apache License 2.0", "lines": 336, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_provider_trace_summarization.py
""" Unit tests for summarization provider trace telemetry context. These tests verify that summarization LLM calls correctly pass telemetry context (agent_id, agent_tags, run_id, step_id) to the provider trace system. """ import uuid from unittest.mock import AsyncMock, MagicMock, patch import pytest from letta.sch...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_provider_trace_summarization.py", "license": "Apache License 2.0", "lines": 362, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_usage_parsing.py
""" Tests for usage statistics parsing through the production adapter path. These tests verify that SimpleLLMRequestAdapter correctly extracts usage statistics from LLM responses, including: 1. Basic usage (prompt_tokens, completion_tokens, total_tokens) 2. Cache-related fields (cached_input_tokens, cache_write_tokens...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_usage_parsing.py", "license": "Apache License 2.0", "lines": 380, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:alembic/versions/539afa667cff_add_telemetry_context_fields_to_.py
"""add telemetry context fields to provider_traces Revision ID: 539afa667cff Revises: a1b2c3d4e5f7 Create Date: 2026-01-16 18:29:29.811385 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "539afa667cff" down_revision: Un...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/539afa667cff_add_telemetry_context_fields_to_.py", "license": "Apache License 2.0", "lines": 23, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/82feb220a9b8_add_source_column_to_provider_traces.py
"""add source column to provider_traces Revision ID: 82feb220a9b8 Revises: 539afa667cff Create Date: 2026-01-18 21:09:59.529688 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "82feb220a9b8" down_revision: Union[str, No...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/82feb220a9b8_add_source_column_to_provider_traces.py", "license": "Apache License 2.0", "lines": 17, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/a1b2c3d4e5f7_add_blocks_conversations_table.py
"""Add blocks_conversations table for conversation-isolated blocks Revision ID: a1b2c3d4e5f7 Revises: cf3c4d025dbc Create Date: 2026-01-14 02:22:00.000000 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "a1b2c3d4e5f7" d...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/a1b2c3d4e5f7_add_blocks_conversations_table.py", "license": "Apache License 2.0", "lines": 38, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/cf3c4d025dbc_add_blocks_tags_table.py
"""Add blocks tags table Revision ID: cf3c4d025dbc Revises: 27de0f58e076 Create Date: 2026-01-08 23:36:00.000000 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op from letta.settings import settings # revision identifiers, used by Alembic. revision: str = "cf3c4d025dbc" down_re...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/cf3c4d025dbc_add_blocks_tags_table.py", "license": "Apache License 2.0", "lines": 46, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/llm_api/chatgpt_oauth_client.py
"""ChatGPT OAuth Client - handles requests to chatgpt.com/backend-api/codex/responses.""" import asyncio import json from typing import Any, AsyncIterator, Dict, List, Optional import httpx from openai.types.responses import ( Response, ResponseCompletedEvent, ResponseContentPartAddedEvent, ResponseCo...
{ "repo_id": "letta-ai/letta", "file_path": "letta/llm_api/chatgpt_oauth_client.py", "license": "Apache License 2.0", "lines": 1059, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/orm/blocks_conversations.py
from sqlalchemy import ForeignKey, Index, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from letta.orm.base import Base class BlocksConversations(Base): """Tracks conversation-specific blocks that override agent defaults for isolated memory.""" __tablename__ = "blocks_conversatio...
{ "repo_id": "letta-ai/letta", "file_path": "letta/orm/blocks_conversations.py", "license": "Apache License 2.0", "lines": 14, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/orm/blocks_tags.py
from datetime import datetime from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: from letta.orm.block import Block from sqlalchemy import Boolean, DateTime, ForeignKey, Index, String, UniqueConstraint, func, text from sqlalchemy.orm import Mapped, mapped_column, relationship from letta.orm.base import ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/orm/blocks_tags.py", "license": "Apache License 2.0", "lines": 29, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/schemas/providers/chatgpt_oauth.py
"""ChatGPT OAuth Provider - uses chatgpt.com/backend-api/codex with OAuth authentication.""" import json from datetime import datetime, timezone from typing import TYPE_CHECKING, Literal, Optional import httpx from pydantic import BaseModel, Field from letta.errors import ErrorCode, LLMAuthenticationError, LLMError ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/providers/chatgpt_oauth.py", "license": "Apache License 2.0", "lines": 313, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/clickhouse_otel_traces.py
import asyncio from typing import Any from urllib.parse import urlparse from letta.helpers.singleton import singleton from letta.settings import settings def _parse_clickhouse_endpoint(endpoint: str) -> tuple[str, int, bool]: parsed = urlparse(endpoint) if parsed.scheme in ("http", "https"): host = ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/clickhouse_otel_traces.py", "license": "Apache License 2.0", "lines": 80, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/clickhouse_provider_traces.py
import asyncio import json from dataclasses import dataclass from typing import Any from urllib.parse import urlparse from letta.helpers.singleton import singleton from letta.schemas.provider_trace import ProviderTrace from letta.settings import settings def _parse_json_maybe(value: str | None) -> dict[str, Any]: ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/clickhouse_provider_traces.py", "license": "Apache License 2.0", "lines": 109, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/provider_trace_backends/base.py
"""Base class for provider trace backends.""" from abc import ABC, abstractmethod from enum import Enum from typing import TYPE_CHECKING if TYPE_CHECKING: from letta.schemas.provider_trace import ProviderTrace from letta.schemas.user import User class ProviderTraceBackend(str, Enum): """Supported provid...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/provider_trace_backends/base.py", "license": "Apache License 2.0", "lines": 54, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:letta/services/provider_trace_backends/clickhouse.py
"""ClickHouse provider trace backend. Writes and reads from the llm_traces table with denormalized columns for cost analytics. """ import json import uuid from typing import TYPE_CHECKING, Optional from letta.log import get_logger from letta.schemas.provider_trace import ProviderTrace from letta.schemas.user import ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/provider_trace_backends/clickhouse.py", "license": "Apache License 2.0", "lines": 161, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/provider_trace_backends/factory.py
"""Factory for creating provider trace backends.""" from functools import lru_cache from letta.services.provider_trace_backends.base import ProviderTraceBackend, ProviderTraceBackendClient def _create_backend(backend: ProviderTraceBackend | str) -> ProviderTraceBackendClient: """Create a single backend instance...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/provider_trace_backends/factory.py", "license": "Apache License 2.0", "lines": 34, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/services/provider_trace_backends/postgres.py
"""PostgreSQL provider trace backend.""" from letta.helpers.json_helpers import json_dumps, json_loads from letta.orm.provider_trace import ProviderTrace as ProviderTraceModel from letta.orm.provider_trace_metadata import ProviderTraceMetadata as ProviderTraceMetadataModel from letta.schemas.provider_trace import Prov...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/provider_trace_backends/postgres.py", "license": "Apache License 2.0", "lines": 91, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/services/provider_trace_backends/socket.py
"""Unix socket provider trace backend.""" import json import os import socket as socket_module import threading import time from datetime import datetime, timezone from typing import Any from letta.log import get_logger from letta.schemas.provider_trace import ProviderTrace from letta.schemas.user import User from le...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/provider_trace_backends/socket.py", "license": "Apache License 2.0", "lines": 117, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/tool_sandbox/typescript_generator.py
"""TypeScript execution script generator for sandbox execution.""" import json import re from typing import Any, Dict, Optional from letta.types import JsonDict, JsonValue def convert_param_to_ts_value(param_type: Optional[str], raw_value: JsonValue) -> str: """ Convert parameter to TypeScript code represen...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/tool_sandbox/typescript_generator.py", "license": "Apache License 2.0", "lines": 192, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:tests/integration_test_override_model.py
""" Integration tests for the override_model functionality. Tests the ability to send messages to agents using a different model than the agent's default configured model, without permanently changing the agent's configuration. Note: Some type: ignore comments are present because the SDK types haven't been regenerate...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_override_model.py", "license": "Apache License 2.0", "lines": 380, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_typescript_tool_execution_sandbox.py
"""Integration tests for TypeScript tool execution in E2B sandbox.""" import uuid import pytest from sqlalchemy import delete from letta.config import LettaConfig from letta.orm.sandbox_config import SandboxConfig, SandboxEnvironmentVariable from letta.schemas.enums import ToolType from letta.schemas.npm_requirement...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_typescript_tool_execution_sandbox.py", "license": "Apache License 2.0", "lines": 573, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_provider_trace_backends.py
"""Unit tests for provider trace backends.""" import json import os import socket import tempfile import threading from unittest.mock import patch import pytest from letta.schemas.provider_trace import ProviderTrace from letta.schemas.user import User from letta.services.provider_trace_backends.base import ProviderT...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_provider_trace_backends.py", "license": "Apache License 2.0", "lines": 320, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:alembic/versions/27de0f58e076_add_conversations_tables_and_run_.py
"""add conversations tables and run conversation_id Revision ID: 27de0f58e076 Revises: ee2b43eea55e Create Date: 2026-01-01 20:36:09.101274 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "27de0f58e076" down_revision: U...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/27de0f58e076_add_conversations_tables_and_run_.py", "license": "Apache License 2.0", "lines": 87, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/ee2b43eea55e_add_request_id_to_steps_table.py
"""add request_id to steps table Revision ID: ee2b43eea55e Revises: 39577145c45d Create Date: 2025-12-17 13:48:08.642245 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "ee2b43eea55e" down_revision: Union[str, None] = "...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/ee2b43eea55e_add_request_id_to_steps_table.py", "license": "Apache License 2.0", "lines": 21, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/llm_api/anthropic_constants.py
# Anthropic-specific constants for the Letta LLM API # Allowlist of simple tools that work with Anthropic's structured outputs (strict mode). # These tools have few parameters and no complex nesting, making them safe for strict mode. # Tools with many optional params or deeply nested structures should use non-strict m...
{ "repo_id": "letta-ai/letta", "file_path": "letta/llm_api/anthropic_constants.py", "license": "Apache License 2.0", "lines": 25, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/llm_api/zai_client.py
from typing import List, Optional from openai import AsyncOpenAI, AsyncStream, OpenAI from openai.types.chat.chat_completion import ChatCompletion from openai.types.chat.chat_completion_chunk import ChatCompletionChunk from letta.helpers.json_helpers import sanitize_unicode_surrogates from letta.llm_api.openai_client...
{ "repo_id": "letta-ai/letta", "file_path": "letta/llm_api/zai_client.py", "license": "Apache License 2.0", "lines": 159, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/orm/conversation.py
import uuid from typing import TYPE_CHECKING, List, Optional from pydantic import TypeAdapter from sqlalchemy import JSON, ForeignKey, Index, String from sqlalchemy.orm import Mapped, mapped_column, relationship from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase from l...
{ "repo_id": "letta-ai/letta", "file_path": "letta/orm/conversation.py", "license": "Apache License 2.0", "lines": 60, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/orm/conversation_messages.py
import uuid from typing import TYPE_CHECKING, Optional from sqlalchemy import Boolean, ForeignKey, Index, Integer, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship from letta.orm.mixins import OrganizationMixin from letta.orm.sqlalchemy_base import SqlalchemyBase if TYPE_CHECKI...
{ "repo_id": "letta-ai/letta", "file_path": "letta/orm/conversation_messages.py", "license": "Apache License 2.0", "lines": 64, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/schemas/conversation.py
from typing import List, Optional from pydantic import BaseModel, Field, field_validator from letta.errors import LettaInvalidArgumentError from letta.schemas.letta_base import OrmMetadataBase from letta.schemas.model import ModelSettingsUnion class Conversation(OrmMetadataBase): """Represents a conversation on...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/conversation.py", "license": "Apache License 2.0", "lines": 73, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/schemas/providers/zai.py
from typing import Literal from letta.log import get_logger logger = get_logger(__name__) from pydantic import Field from letta.schemas.enums import ProviderCategory, ProviderType from letta.schemas.llm_config import LLMConfig from letta.schemas.providers.openai import OpenAIProvider # Z.ai model context windows #...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/providers/zai.py", "license": "Apache License 2.0", "lines": 57, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/server/rest_api/middleware/request_id.py
""" Middleware for extracting and propagating API request IDs from cloud-api. Uses a pure ASGI middleware pattern to properly propagate the request_id to streaming responses. BaseHTTPMiddleware has a known limitation where contextvars are not propagated to streaming response generators. See: https://github.com/encode/...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/middleware/request_id.py", "license": "Apache License 2.0", "lines": 47, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:letta/server/rest_api/routers/v1/conversations.py
from datetime import timedelta from typing import Annotated, List, Literal, Optional from uuid import uuid4 from fastapi import APIRouter, Body, Depends, HTTPException, Query, status from pydantic import BaseModel, Field from starlette.responses import StreamingResponse from letta.agents.agent_loop import AgentLoop f...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/conversations.py", "license": "Apache License 2.0", "lines": 711, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/conversation_manager.py
from typing import TYPE_CHECKING, Dict, List, Optional if TYPE_CHECKING: pass # Import AgentState outside TYPE_CHECKING for @enforce_types decorator from sqlalchemy import and_, asc, delete, desc, func, nulls_last, or_, select from letta.errors import LettaInvalidArgumentError from letta.helpers.datetime_helpers...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/conversation_manager.py", "license": "Apache License 2.0", "lines": 714, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/mcp/fastmcp_client.py
"""FastMCP-based MCP clients with server-side OAuth support. This module provides MCP client implementations using the FastMCP library, with support for server-side OAuth flows where authorization URLs are forwarded to web clients instead of opening a browser. These clients replace the existing AsyncSSEMCPClient and ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/mcp/fastmcp_client.py", "license": "Apache License 2.0", "lines": 287, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/mcp/server_side_oauth.py
"""Server-side OAuth for FastMCP client that works with web app flows. This module provides a custom OAuth implementation that: 1. Forwards authorization URLs via callback instead of opening a browser 2. Receives auth codes from an external source (web app callback) instead of running a local server This is designed ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/mcp/server_side_oauth.py", "license": "Apache License 2.0", "lines": 185, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:tests/adapters/test_letta_llm_stream_adapter_error_handling.py
import anthropic import httpx import openai import pytest from anthropic.types.beta import ( BetaMessage, BetaRawMessageStartEvent, BetaRawMessageStopEvent, BetaUsage, ) from google.genai import errors as google_errors from letta.adapters.letta_llm_stream_adapter import LettaLLMStreamAdapter from letta...
{ "repo_id": "letta-ai/letta", "file_path": "tests/adapters/test_letta_llm_stream_adapter_error_handling.py", "license": "Apache License 2.0", "lines": 278, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_client_side_tools.py
""" Integration tests for client-side tools passed in the request. These tests verify that: 1. Client-side tools can be specified in the request without pre-registration on the server 2. When the agent calls a client-side tool, execution pauses (stop_reason=requires_approval) 3. Client can provide tool returns via the...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_client_side_tools.py", "license": "Apache License 2.0", "lines": 342, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_conversations_sdk.py
""" Integration tests for the Conversations API using the SDK. """ import uuid import pytest import requests from letta_client import Letta @pytest.fixture def client(server_url: str) -> Letta: """Create a Letta client.""" return Letta(base_url=server_url) @pytest.fixture def agent(client: Letta): """...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_conversations_sdk.py", "license": "Apache License 2.0", "lines": 1035, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/managers/test_agent_manager_block_update.py
import pytest # Import shared fixtures and constants from conftest from conftest import DEFAULT_EMBEDDING_CONFIG from letta.orm.errors import NoResultFound from letta.schemas.agent import CreateAgent from letta.schemas.block import Block as PydanticBlock, BlockUpdate from letta.schemas.llm_config import LLMConfig fro...
{ "repo_id": "letta-ai/letta", "file_path": "tests/managers/test_agent_manager_block_update.py", "license": "Apache License 2.0", "lines": 62, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/managers/test_conversation_manager.py
""" Tests for ConversationManager. """ import pytest from letta.orm.errors import NoResultFound from letta.schemas.conversation import CreateConversation, UpdateConversation from letta.server.server import SyncServer from letta.services.conversation_manager import ConversationManager # ==============================...
{ "repo_id": "letta-ai/letta", "file_path": "tests/managers/test_conversation_manager.py", "license": "Apache License 2.0", "lines": 1100, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:alembic/versions/39577145c45d_add_project_constraint_on_tools.py
"""add project constraint on tools Revision ID: 39577145c45d Revises: d0880aae6cee Create Date: 2025-12-17 15:46:06.184858 """ from typing import Sequence, Union from alembic import op # revision identifiers, used by Alembic. revision: str = "39577145c45d" down_revision: Union[str, None] = "d0880aae6cee" branch_la...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/39577145c45d_add_project_constraint_on_tools.py", "license": "Apache License 2.0", "lines": 22, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/llm_api/error_utils.py
"""Shared helpers for provider error detection/mapping. Keep these utilities free of heavy imports to avoid circular dependencies between LLM clients (provider-specific) and streaming interfaces. """ def is_context_window_overflow_message(msg: str) -> bool: """Best-effort detection for context window overflow er...
{ "repo_id": "letta-ai/letta", "file_path": "letta/llm_api/error_utils.py", "license": "Apache License 2.0", "lines": 32, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:alembic/versions/175dd10fb916_add_prompt_tokens_details_to_steps.py
"""Add prompt_tokens_details to steps table Revision ID: 175dd10fb916 Revises: b1c2d3e4f5a6 Create Date: 2025-11-28 12:00:00.000000 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "175dd10fb916" down_revision: Union[str...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/175dd10fb916_add_prompt_tokens_details_to_steps.py", "license": "Apache License 2.0", "lines": 19, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/2e5e90d3cdf8_add_project_id_to_tools.py
"""add project_id to tools Revision ID: 2e5e90d3cdf8 Revises: af842aa6f743 Create Date: 2025-12-03 11:55:57.355341 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "2e5e90d3cdf8" down_revision: Union[str, None] = "af842a...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/2e5e90d3cdf8_add_project_id_to_tools.py", "license": "Apache License 2.0", "lines": 17, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/af842aa6f743_add_tool_indexes_for_organization_id.py
"""add tool indexes for organization_id Revision ID: af842aa6f743 Revises: 175dd10fb916 Create Date: 2025-12-07 15:30:43.407495 """ from typing import Sequence, Union from alembic import op # revision identifiers, used by Alembic. revision: str = "af842aa6f743" down_revision: Union[str, None] = "175dd10fb916" bran...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/af842aa6f743_add_tool_indexes_for_organization_id.py", "license": "Apache License 2.0", "lines": 22, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/d0880aae6cee_add_compaction_settings_to_agents_table.py
"""add compaction_settings to agents table Revision ID: d0880aae6cee Revises: 2e5e90d3cdf8 Create Date: 2025-12-10 16:17:23.595775 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op from letta.orm.custom_columns import CompactionSettingsColumn # revision identifiers, used by Ale...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/d0880aae6cee_add_compaction_settings_to_agents_table.py", "license": "Apache License 2.0", "lines": 18, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/prompts/summarizer_prompt.py
ALL_WORD_LIMIT = 500 SLIDING_WORD_LIMIT = 300 ALL_PROMPT = f"""Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions. This summary should be thorough in capturing technical details, code patterns, and architectural decisio...
{ "repo_id": "letta-ai/letta", "file_path": "letta/prompts/summarizer_prompt.py", "license": "Apache License 2.0", "lines": 154, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:letta/server/rest_api/proxy_helpers.py
""" Shared helper functions for Anthropic-compatible proxy endpoints. These helpers are used by both the Anthropic and Z.ai proxy routers to reduce code duplication. """ import json from fastapi import Request from letta.log import get_logger from letta.server.rest_api.utils import capture_and_persist_messages from...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/proxy_helpers.py", "license": "Apache License 2.0", "lines": 470, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/zai.py
import asyncio import httpx from fastapi import APIRouter, Depends, Request from fastapi.responses import Response, StreamingResponse from letta.log import get_logger from letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_server from letta.server.rest_api.proxy_helpers import ( build_...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/zai.py", "license": "Apache License 2.0", "lines": 290, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/summarizer/summarizer_all.py
from typing import List, Optional from letta.log import get_logger from letta.otel.tracing import trace_method from letta.schemas.llm_config import LLMConfig from letta.schemas.message import Message, MessageRole from letta.schemas.user import User from letta.services.summarizer.summarizer import simple_summary from l...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/summarizer/summarizer_all.py", "license": "Apache License 2.0", "lines": 73, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/services/summarizer/summarizer_config.py
from typing import Literal from pydantic import BaseModel, Field from letta.prompts.summarizer_prompt import ALL_PROMPT, SELF_ALL_PROMPT, SELF_SLIDING_PROMPT, SLIDING_PROMPT from letta.schemas.enums import ProviderType from letta.schemas.model import ModelSettingsUnion from letta.settings import summarizer_settings ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/summarizer/summarizer_config.py", "license": "Apache License 2.0", "lines": 61, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/summarizer/summarizer_sliding_window.py
from typing import TYPE_CHECKING, List, Optional, Tuple if TYPE_CHECKING: from letta.schemas.tool import Tool from letta.log import get_logger from letta.otel.tracing import trace_method from letta.schemas.enums import MessageRole from letta.schemas.llm_config import LLMConfig from letta.schemas.message import Me...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/summarizer/summarizer_sliding_window.py", "license": "Apache License 2.0", "lines": 187, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:tests/integration_test_token_counters.py
""" Integration tests for token counting APIs. These tests verify that the token counting implementations actually hit the real APIs for Anthropic, Google Gemini, and OpenAI (tiktoken) by calling get_context_window on an imported agent. """ import json import os import pytest from letta.config import LettaConfig fr...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_token_counters.py", "license": "Apache License 2.0", "lines": 181, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_usage_tracking.py
""" Integration tests for advanced usage tracking (cache tokens, reasoning tokens). These tests verify that: 1. Cache token data (cached_input_tokens, cache_write_tokens) is captured from providers 2. Reasoning token data is captured from reasoning models 3. The data flows correctly through streaming and non-streaming...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_usage_tracking.py", "license": "Apache License 2.0", "lines": 394, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/managers/test_cancellation.py
""" Tests for agent cancellation at different points in the execution loop. These tests use mocking and deterministic control to test cancellation at specific points in the agent execution flow, covering all the issues documented in CANCELLATION_ISSUES.md. """ import asyncio import pytest from letta.agents.agent_lo...
{ "repo_id": "letta-ai/letta", "file_path": "tests/managers/test_cancellation.py", "license": "Apache License 2.0", "lines": 1442, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_message_serialization.py
from letta.llm_api.openai_client import fill_image_content_in_responses_input from letta.schemas.enums import MessageRole from letta.schemas.letta_message_content import Base64Image, ImageContent, TextContent from letta.schemas.message import Message def _user_message_with_image_first(text: str) -> Message: image...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_message_serialization.py", "license": "Apache License 2.0", "lines": 24, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_prompt_caching.py
""" Integration tests for prompt caching validation. These tests verify that our LLM clients properly enable caching for each provider: - OpenAI: Automatic caching (≥1024 tokens) - Anthropic: Requires cache_control breakpoints (≥1024 tokens for Sonnet 4.5) - Gemini: Implicit caching on 2.5 models (≥1024 tokens for 2.5...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_prompt_caching.py", "license": "Apache License 2.0", "lines": 932, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_internal_agents_count.py
from typing import List import httpx import pytest from letta_client import Letta from letta.schemas.agent import AgentState @pytest.fixture(scope="function") def test_agents(client: Letta) -> List[AgentState]: """ Creates test agents - some hidden, some not hidden. Cleans them up after the test. ""...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_internal_agents_count.py", "license": "Apache License 2.0", "lines": 121, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:letta/monitoring/event_loop_watchdog.py
""" Lightweight thread-based watchdog to detect event loop hangs. Runs independently and won't interfere with tests or normal operation. """ import asyncio import threading import time import traceback from collections import defaultdict from typing import Optional from letta.log import get_logger logger = get_logge...
{ "repo_id": "letta-ai/letta", "file_path": "letta/monitoring/event_loop_watchdog.py", "license": "Apache License 2.0", "lines": 257, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/anthropic.py
import asyncio import httpx from fastapi import APIRouter, Depends, Request from fastapi.responses import Response, StreamingResponse from letta.log import get_logger from letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_server from letta.server.rest_api.proxy_helpers import ( build_...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/anthropic.py", "license": "Apache License 2.0", "lines": 293, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/passages.py
from datetime import datetime from typing import List, Literal, Optional from fastapi import APIRouter, Body, Depends from pydantic import BaseModel, Field from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.enums import TagMatchMode from letta.schemas.passage import Passage from letta.schem...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/passages.py", "license": "Apache License 2.0", "lines": 114, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/sandbox_credentials_service.py
import logging import os from typing import Any, Dict, Optional import httpx from letta.schemas.user import User logger = logging.getLogger(__name__) class SandboxCredentialsService: """Service for fetching sandbox credentials from a webhook.""" def __init__(self): self.credentials_webhook_url = o...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/sandbox_credentials_service.py", "license": "Apache License 2.0", "lines": 63, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/sandbox_credentials_service_test.py
""" Test for sandbox credentials service functionality. To run this test: python -m pytest letta/services/sandbox_credentials_service_test.py -v To test with actual webhook: export SANDBOX_CREDENTIALS_WEBHOOK=https://your-webhook-url.com/endpoint export SANDBOX_CREDENTIALS_KEY=your-secret-key python -...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/sandbox_credentials_service_test.py", "license": "Apache License 2.0", "lines": 111, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:test_watchdog_hang.py
#!/usr/bin/env python3 """ Test script to verify the watchdog detects event loop hangs. Run this to validate the watchdog works before deploying. """ import asyncio import logging import sys import time from pathlib import Path # Setup logging to see watchdog output logging.basicConfig(level=logging.INFO, format="%(a...
{ "repo_id": "letta-ai/letta", "file_path": "test_watchdog_hang.py", "license": "Apache License 2.0", "lines": 74, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:tests/sdk/search_test.py
""" End-to-end tests for passage and message search endpoints using the SDK client. These tests verify that the /v1/passages/search and /v1/messages/search endpoints work correctly with Turbopuffer integration, including vector search, FTS, hybrid search, filtering, and pagination. """ import time import uuid from da...
{ "repo_id": "letta-ai/letta", "file_path": "tests/sdk/search_test.py", "license": "Apache License 2.0", "lines": 590, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:alembic/versions/2dbb2cf49e07_add_models_table.py
"""add models table Revision ID: 2dbb2cf49e07 Revises: a1b2c3d4e5f6 Create Date: 2025-11-06 14:49:10.902099 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "2dbb2cf49e07" down_revision: Union[str, None] = "a1b2c3d4e5f6"...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/2dbb2cf49e07_add_models_table.py", "license": "Apache License 2.0", "lines": 56, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/89fd4648866b_add_last_stop_reason_to_agent_state.py
"""add last_stop_reason to agent state Revision ID: 89fd4648866b Revises: f6cd5a1e519d Create Date: 2025-10-27 16:55:54.383688 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "89fd4648866b" down_revision: Union[str, Non...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/89fd4648866b_add_last_stop_reason_to_agent_state.py", "license": "Apache License 2.0", "lines": 21, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/a1b2c3d4e5f6_add_index_to_step_metrics_run_id.py
"""add index to step_metrics run_id Revision ID: a1b2c3d4e5f6 Revises: d798609d65ff Create Date: 2025-11-11 19:16:00.000000 """ from typing import Sequence, Union from alembic import op from letta.settings import settings # revision identifiers, used by Alembic. revision: str = "a1b2c3d4e5f6" down_revision: Union[...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/a1b2c3d4e5f6_add_index_to_step_metrics_run_id.py", "license": "Apache License 2.0", "lines": 25, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/b1c2d3e4f5a6_drop_unused_and_redundant_indexes.py
"""drop unused and redundant indexes Revision ID: b1c2d3e4f5a6 Revises: 2dbb2cf49e07 Create Date: 2025-11-11 21:16:00.000000 """ from typing import Sequence, Union from alembic import op from letta.settings import settings # revision identifiers, used by Alembic. revision: str = "b1c2d3e4f5a6" down_revision: Union...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/b1c2d3e4f5a6_drop_unused_and_redundant_indexes.py", "license": "Apache License 2.0", "lines": 57, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/d798609d65ff_add_index_on_messages_step_id.py
"""add_index_on_messages_step_id Revision ID: d798609d65ff Revises: 89fd4648866b Create Date: 2025-11-07 15:43:59.446292 """ from typing import Sequence, Union from alembic import op from letta.settings import settings # revision identifiers, used by Alembic. revision: str = "d798609d65ff" down_revision: Union[str...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/d798609d65ff_add_index_on_messages_step_id.py", "license": "Apache License 2.0", "lines": 23, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/exceptions/logging.py
""" Helper utilities for structured exception logging. Use these when you need to add context to exceptions before raising them. """ from typing import Any, Dict, Optional from letta.log import get_logger logger = get_logger(__name__) def log_and_raise( exception: Exception, message: str, context: Opti...
{ "repo_id": "letta-ai/letta", "file_path": "letta/exceptions/logging.py", "license": "Apache License 2.0", "lines": 113, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:letta/helpers/tool_helpers.py
import hashlib from letta.constants import MODAL_VERSION_HASH_LENGTH from letta.schemas.tool import Tool def _serialize_dependencies(tool: Tool) -> str: """ Serialize dependencies in a consistent way for hashing. TODO: This should be improved per LET-3770 to ensure consistent ordering. For now, we co...
{ "repo_id": "letta-ai/letta", "file_path": "letta/helpers/tool_helpers.py", "license": "Apache License 2.0", "lines": 52, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
documentation
letta-ai/letta:letta/log_context.py
from contextvars import ContextVar from typing import Any, Optional _log_context: ContextVar[dict[str, Any]] = ContextVar("log_context", default={}) def set_log_context(key: str, value: Any) -> None: ctx = _log_context.get().copy() ctx[key] = value _log_context.set(ctx) def get_log_context(key: Optiona...
{ "repo_id": "letta-ai/letta", "file_path": "letta/log_context.py", "license": "Apache License 2.0", "lines": 22, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/orm/provider_model.py
from typing import TYPE_CHECKING, Optional from sqlalchemy import Boolean, ForeignKey, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column, relationship from letta.orm.sqlalchemy_base import SqlalchemyBase from letta.schemas.provider_model import ProviderModel as PydanticProviderModel if TYPE_C...
{ "repo_id": "letta-ai/letta", "file_path": "letta/orm/provider_model.py", "license": "Apache License 2.0", "lines": 59, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/schemas/model.py
from typing import Annotated, Literal, Optional, Union from pydantic import BaseModel, Field from letta.schemas.embedding_config import EmbeddingConfig from letta.schemas.enums import ProviderCategory, ProviderType from letta.schemas.llm_config import LLMConfig from letta.schemas.response_format import ResponseFormat...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/model.py", "license": "Apache License 2.0", "lines": 445, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/schemas/provider_model.py
from typing import Optional from pydantic import Field from letta.schemas.enums import PrimitiveType from letta.schemas.letta_base import OrmMetadataBase class ProviderModelBase(OrmMetadataBase): __id_prefix__ = PrimitiveType.PROVIDER_MODEL.value class ProviderModel(ProviderModelBase): """ Pydantic mo...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/provider_model.py", "license": "Apache License 2.0", "lines": 54, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/global_exception_handler.py
""" Global exception handlers for non-request exceptions (background tasks, startup, etc.) """ import sys import threading import traceback from letta.log import get_logger logger = get_logger(__name__) def setup_global_exception_handlers(): """ Set up global exception handlers to catch exceptions that occ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/global_exception_handler.py", "license": "Apache License 2.0", "lines": 91, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/server/rest_api/middleware/logging.py
""" Unified logging middleware that enriches log context and ensures exceptions are logged. """ import traceback from typing import Callable from starlette.middleware.base import BaseHTTPMiddleware from starlette.requests import Request from letta.log import get_logger from letta.log_context import clear_log_context...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/middleware/logging.py", "license": "Apache License 2.0", "lines": 139, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/internal_agents.py
from fastapi import APIRouter, Body, Depends, Query from letta.schemas.block import Block, BlockUpdate from letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_server from letta.server.server import SyncServer from letta.validators import AgentId router = APIRouter(prefix="/_internal_agents...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/internal_agents.py", "license": "Apache License 2.0", "lines": 42, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/server/rest_api/routers/v1/internal_blocks.py
from typing import TYPE_CHECKING, List, Literal, Optional from fastapi import APIRouter, Body, Depends, Query from letta.schemas.agent import AgentState from letta.schemas.block import Block, CreateBlock from letta.server.rest_api.dependencies import HeaderParams, get_headers, get_letta_server from letta.server.serve...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/internal_blocks.py", "license": "Apache License 2.0", "lines": 162, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/webhook_service.py
import logging import os import httpx logger = logging.getLogger(__name__) class WebhookService: """Service for sending webhook notifications when steps complete.""" def __init__(self): self.webhook_url = os.getenv("STEP_COMPLETE_WEBHOOK") self.webhook_key = os.getenv("STEP_COMPLETE_KEY") ...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/webhook_service.py", "license": "Apache License 2.0", "lines": 43, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/services/webhook_service_test.py
""" Simple test to verify webhook service functionality. To run this test: python -m pytest letta/services/webhook_service_test.py -v To test with actual webhook: export STEP_COMPLETE_WEBHOOK=https://your-webhook-url.com/endpoint export STEP_COMPLETE_KEY=your-secret-key python -m pytest letta/services...
{ "repo_id": "letta-ai/letta", "file_path": "letta/services/webhook_service_test.py", "license": "Apache License 2.0", "lines": 86, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_cancellation.py
import asyncio import json import os import threading from typing import Any, List import pytest from dotenv import load_dotenv from letta_client import AsyncLetta from letta_client.types import MessageCreateParam from letta.log import get_logger from letta.schemas.agent import AgentState from letta.schemas.enums imp...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_cancellation.py", "license": "Apache License 2.0", "lines": 163, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/integration_test_modal.py
import os import secrets import string import uuid from pathlib import Path from unittest.mock import patch import pytest from sqlalchemy import delete from letta.config import LettaConfig from letta.functions.function_sets.base import core_memory_append, core_memory_replace from letta.orm.sandbox_config import Sandb...
{ "repo_id": "letta-ai/letta", "file_path": "tests/integration_test_modal.py", "license": "Apache License 2.0", "lines": 604, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_exception_logging.py
""" Tests for global exception logging system. """ import asyncio from unittest.mock import patch import pytest from fastapi import FastAPI from fastapi.testclient import TestClient from letta.exceptions.logging import add_exception_context, log_and_raise, log_exception from letta.server.rest_api.middleware.logging ...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_exception_logging.py", "license": "Apache License 2.0", "lines": 179, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_log_context.py
import json import logging from io import StringIO from letta.log import JSONFormatter, LogContextFilter from letta.log_context import clear_log_context, get_log_context, remove_log_context, set_log_context, update_log_context class TestLogContext: def test_set_log_context(self): clear_log_context() ...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_log_context.py", "license": "Apache License 2.0", "lines": 120, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_log_context_middleware.py
from unittest.mock import patch import pytest from fastapi import FastAPI from fastapi.testclient import TestClient import letta.server.rest_api.routers.v1.git_http as git_http_router from letta.log_context import get_log_context from letta.server.rest_api.middleware import LoggingMiddleware @pytest.fixture def app...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_log_context_middleware.py", "license": "Apache License 2.0", "lines": 134, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_server_providers.py
"""Tests for provider initialization via ProviderManager.sync_base_providers and provider model persistence.""" import json import uuid from unittest.mock import AsyncMock, MagicMock, patch import pytest from letta.orm.errors import UniqueConstraintViolationError from letta.schemas.agent import CreateAgent from lett...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_server_providers.py", "license": "Apache License 2.0", "lines": 2785, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:tests/test_temporal_metrics_local.py
""" Local test for temporal metrics. Run with: uv run pytest tests/test_temporal_metrics_local.py -v -s """ import os from unittest.mock import patch import pytest from letta.agents.temporal.metrics import ( ActivityMetrics, TemporalMetrics, WorkflowMetrics, ) @pytest.fixture(autouse=True) def setup_me...
{ "repo_id": "letta-ai/letta", "file_path": "tests/test_temporal_metrics_local.py", "license": "Apache License 2.0", "lines": 102, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
test
letta-ai/letta:alembic/versions/066857381578_add_approvals_field_to_messages.py
"""add approvals field to messages Revision ID: 066857381578 Revises: c734cfc0d595 Create Date: 2025-10-09 17:56:07.333221 """ from typing import Sequence, Union import sqlalchemy as sa import letta.orm from alembic import op from letta.settings import settings # revision identifiers, used by Alembic. revision: s...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/066857381578_add_approvals_field_to_messages.py", "license": "Apache License 2.0", "lines": 29, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/6756d04c3ddb_add_tools_used_field_to_run_metrics_.py
"""Add tools_used field to run_metrics table Revision ID: 6756d04c3ddb Revises: e67961ed7c32 Create Date: 2025-10-17 14:52:53.601368 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "6756d04c3ddb" down_revision: Union[st...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/6756d04c3ddb_add_tools_used_field_to_run_metrics_.py", "license": "Apache License 2.0", "lines": 21, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/8149a781ac1b_backfill_encrypted_columns_for_.py
"""backfill encrypted columns for providers, mcp, sandbox Revision ID: 8149a781ac1b Revises: 066857381578 Create Date: 2025-10-13 13:35:55.929562 """ import os from typing import Sequence, Union import sqlalchemy as sa from sqlalchemy import String, Text from sqlalchemy.sql import column, table from alembic import...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/8149a781ac1b_backfill_encrypted_columns_for_.py", "license": "Apache License 2.0", "lines": 291, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:alembic/versions/c6c43222e2de_add_mcp_tools_table.py
"""Add mcp_tools table Revision ID: c6c43222e2de Revises: 6756d04c3ddb Create Date: 2025-10-20 17:25:54.334037 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "c6c43222e2de" down_revision: Union[str, None] = "6756d04c3d...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/c6c43222e2de_add_mcp_tools_table.py", "license": "Apache License 2.0", "lines": 37, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/e67961ed7c32_add_enable_parallel_execution_to_tools_table.py
"""Add enable_parallel_execution to Tools table Revision ID: e67961ed7c32 Revises: 8149a781ac1b Create Date: 2025-10-17 15:47:00.447066 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision: str = "e67961ed7c32" down_revision: Union...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/e67961ed7c32_add_enable_parallel_execution_to_tools_table.py", "license": "Apache License 2.0", "lines": 21, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:alembic/versions/f6cd5a1e519d_add_embedding_config_field_to_archives_.py
"""Add embedding config field to Archives table Revision ID: f6cd5a1e519d Revises: c6c43222e2de Create Date: 2025-10-23 16:33:53.661122 """ import json from typing import Sequence, Union import sqlalchemy as sa from sqlalchemy import text import letta.orm from alembic import op from letta.schemas.embedding_config ...
{ "repo_id": "letta-ai/letta", "file_path": "alembic/versions/f6cd5a1e519d_add_embedding_config_field_to_archives_.py", "license": "Apache License 2.0", "lines": 59, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_simple
letta-ai/letta:letta/groups/sleeptime_multi_agent_v4.py
from collections.abc import AsyncGenerator from datetime import datetime, timezone from letta.agents.letta_agent_v3 import LettaAgentV3 from letta.constants import DEFAULT_MAX_STEPS from letta.groups.helpers import stringify_message from letta.otel.tracing import trace_method from letta.schemas.agent import AgentState...
{ "repo_id": "letta-ai/letta", "file_path": "letta/groups/sleeptime_multi_agent_v4.py", "license": "Apache License 2.0", "lines": 242, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/schemas/mcp_server.py
from datetime import datetime from typing import Annotated, Any, Dict, List, Literal, Optional, Union from urllib.parse import urlparse from pydantic import Field, field_validator from letta.functions.mcp_client.types import ( MCP_AUTH_TOKEN_BEARER_PREFIX, MCPServerType, ) from letta.orm.mcp_oauth import OAut...
{ "repo_id": "letta-ai/letta", "file_path": "letta/schemas/mcp_server.py", "license": "Apache License 2.0", "lines": 371, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/chat_completions.py
from typing import Optional, Union from fastapi import APIRouter, Body, Depends from fastapi.responses import StreamingResponse from openai.types.chat import ChatCompletion from openai.types.chat.chat_completion_message_param import ChatCompletionMessageParam from pydantic import BaseModel, Field from letta.errors im...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/chat_completions.py", "license": "Apache License 2.0", "lines": 123, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/internal_runs.py
from datetime import datetime from typing import List, Literal, Optional from fastapi import APIRouter, Depends, Query from letta.schemas.enums import ComparisonOperator, RunStatus from letta.schemas.letta_stop_reason import StopReasonType from letta.schemas.run import Run from letta.server.rest_api.dependencies impo...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/internal_runs.py", "license": "Apache License 2.0", "lines": 119, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex
letta-ai/letta:letta/server/rest_api/routers/v1/mcp_servers.py
from typing import AsyncGenerator, List, Optional, Union from fastapi import APIRouter, Body, Depends, Request from httpx import HTTPStatusError from starlette.responses import StreamingResponse from letta.errors import LettaMCPConnectionError from letta.functions.mcp_client.types import SSEServerConfig, StdioServerC...
{ "repo_id": "letta-ai/letta", "file_path": "letta/server/rest_api/routers/v1/mcp_servers.py", "license": "Apache License 2.0", "lines": 274, "canary_id": -1, "canary_value": "", "pii_type": "", "provider": "", "regex_pattern": "", "repetition": -1, "template": "" }
function_complex