Skip to content

Deps

AgentDeps dataclass

Dependency Injection container for PydanticAI Agents.

This class encapsulates external resources (specifically the database path) that need to be passed into the Agent's runtime context. It allows the Agent to establish connections dynamically during execution.

Attributes:

Name Type Description
db_path str

The filesystem path to the DuckDB database file.

Source code in api/src/agents/deps.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@dataclass
class AgentDeps:
    """
    Dependency Injection container for PydanticAI Agents.

    This class encapsulates external resources (specifically the database path)
    that need to be passed into the Agent's runtime context. It allows the Agent
    to establish connections dynamically during execution.

    Attributes:
        db_path (str): The filesystem path to the DuckDB database file.
    """

    db_path: str

    def get_db_connection(self, read_only: bool = True) -> DuckDBPyConnection:
        """
        Creates a new connection to the DuckDB database.

        Args:
            read_only (bool): Safety flag to prevent accidental writes. Defaults to `True`.

        Returns:
            DuckDBPyConnection: An active database connection object.
        """
        return duckdb.connect(self.db_path, read_only=read_only)

get_db_connection(read_only=True)

Creates a new connection to the DuckDB database.

Parameters:

Name Type Description Default
read_only bool

Safety flag to prevent accidental writes. Defaults to True.

True

Returns:

Name Type Description
DuckDBPyConnection DuckDBPyConnection

An active database connection object.

Source code in api/src/agents/deps.py
22
23
24
25
26
27
28
29
30
31
32
def get_db_connection(self, read_only: bool = True) -> DuckDBPyConnection:
    """
    Creates a new connection to the DuckDB database.

    Args:
        read_only (bool): Safety flag to prevent accidental writes. Defaults to `True`.

    Returns:
        DuckDBPyConnection: An active database connection object.
    """
    return duckdb.connect(self.db_path, read_only=read_only)