Skip to content

Schema

Modules concerning the schemas used throughout the Gen AI applications.

Chunk

Bases: BaseModel

Represents a chunk of content retrieved from a vector store.

Attributes:

Name Type Description
id str

A unique identifier for the chunk. Defaults to a random UUID.

content str | bytes

The content of the chunk, either text or binary.

metadata dict[str, Any]

Additional metadata associated with the chunk. Defaults to an empty dictionary.

score float | None

Similarity score of the chunk (if available). Defaults to None.

__repr__()

Return a string representation of the Chunk.

Returns:

Name Type Description
str str

The string representation of the Chunk.

is_binary()

Check if the content is binary.

Returns:

Name Type Description
bool bool

True if the content is binary, False otherwise.

is_text()

Check if the content is text.

Returns:

Name Type Description
bool bool

True if the content is text, False otherwise.

validate_content(value) classmethod

Validate the content of the Chunk.

This is a class method required by Pydantic validators. As such, it follows its signature and conventions.

Parameters:

Name Type Description Default
value str | bytes

The content to validate.

required

Returns:

Type Description
str | bytes

str | bytes: The validated content.

Raises:

Type Description
ValueError

If the content is empty or not a string or bytes.

Component

Bases: ABC

An abstract base class for all components used throughout the Gen AI applications.

Every instance of Component has access to class-level _default_log_level and _logger, as detailed below. For components that require high observability, it is recommended to set _default_log_level to logging.INFO or higher.

Example:

class MyComponent(Component):
    _default_log_level = logging.INFO

    def _run(self, **kwargs: Any) -> Any:
        return "Hello, World!"

Attributes:

Name Type Description
run_profile RunProfile

The profile of the _run method. This property is used by Pipeline to analyze the input requirements of the component. In most cases, unless you are working with Pipeline and PipelineSteps, you will not need to use this property.

Do not override this property in your subclass.

You also do not need to write this attribute in your component's docstring.

_default_log_level int

The default log level for the component. Defaults to DEBUG.

_logger Logger

The logger instance for the component.

run_profile: RunProfile property

Analyzes the _run method and retrieves its profile.

This property method analyzes the _run method of the class to generate a RunProfile object. It also updates the method signatures for methods that fully utilize the arguments.

Returns:

Name Type Description
RunProfile RunProfile

The profile of the _run method, including method signatures for full-pass argument usages.

run(**kwargs) async

Runs the operations defined for the component.

This method emits the provided input arguments using an EventEmitter instance if available, executes a process defined in the _run method, and emits the resulting output if the EventEmitter is provided.

Parameters:

Name Type Description Default
**kwargs Any

A dictionary of arguments to be processed. May include an event_emitter key with an EventEmitter instance.

{}

Returns:

Name Type Description
Any Any

The result of the _run method.

Event

Bases: BaseModel

A data class to store an event attributes.

Attributes:

Name Type Description
id str

The ID of the event. Defaults to None.

value str | dict[str, Any]

The value of the event. Defaults to an empty string.

level EventLevel

The severity level of the event. Defaults to EventLevel.INFO.

type str

The type of the event. Defaults to EventType.RESPONSE.

timestamp datetime

The timestamp of the event. Defaults to the current timestamp.

metadata dict[str, Any]

The metadata of the event. Defaults to an empty dictionary.

serialize_level(level)

Serializes an EventLevel object into its string representation.

This method serializes the given EventLevel object by returning its name as a string.

Parameters:

Name Type Description Default
level EventLevel

The EventLevel object to be serialized.

required

Returns:

Name Type Description
str str

The name of the EventLevel object.

Tool

Bases: BaseModel

Model Context Protocol (MCP)-style Tool definition.

This class represents a tool that can be used by a language model to interact with the outside world, following the Model Context Protocol (MCP) specification. Tools are defined by their name, description, input and output schemas, and an optional function implementation.

The Tool class supports flexible schema handling, accepting either: 1. Dictionary-based JSON Schema objects 2. Pydantic BaseModel classes

When a Pydantic model is provided, it is automatically converted to a JSON Schema using Pydantic's model_json_schema() method.

Supported use cases include: 1. Creating a tool with dictionary schemas for input/output 2. Creating a tool with Pydantic models for input/output 3. Using the @tool decorator to create a tool from a function's type hints

Attributes:

Name Type Description
name str

A string identifier for the tool, used for programmatic access.

description str

A human-readable description of what the tool does.

input_schema dict[str, Any] | type[BaseModel]

JSON Schema object or Pydantic model defining the expected parameters.

title str | None

Optional display name for the tool.

output_schema dict[str, Any] | type[BaseModel] | None

Optional JSON Schema object or Pydantic model defining the structure of the output.

annotations dict[str, Any] | None

Optional additional tool information for enriching the tool definition. According to MCP, display name precedence is: title, annotations.title, then name.

meta dict[str, Any] | None

Optional additional metadata for internal use by the system. Unlike annotations which provide additional information about the tool for clients, meta is meant for private system-level metadata that shouldn't be exposed to end users.

func Callable

The callable function that implements this tool's behavior.

is_async bool

Whether the tool's function is asynchronous.

__signature__: inspect.Signature property

Expose the underlying function's signature for introspection.

Returns:

Type Description
Signature

inspect.Signature: Signature of the underlying function, or an empty signature if missing.

__call__(*args, **kwargs)

Call the underlying function.

Mirrors the original function's call semantics: 1. If the underlying function is synchronous, returns the result directly. 2. If asynchronous, returns a coroutine that must be awaited.

Parameters:

Name Type Description Default
*args Any

Positional arguments for the function.

()
**kwargs Any

Keyword arguments for the function.

{}

Returns:

Name Type Description
Any Any

Result or coroutine depending on the underlying function.

Raises:

Type Description
ValueError

If no implementation function is defined.

from_google_adk(function_declaration, func=None) classmethod

Create a Tool from a Google ADK function declaration.

Parameters:

Name Type Description Default
function_declaration Any

Google ADK function declaration to convert.

required
func Callable | None

Optional implementation callable for the tool.

None

Returns:

Name Type Description
Tool 'Tool'

Tool instance derived from the Google ADK definition.

from_langchain(langchain_tool) classmethod

Create a Tool from a LangChain tool instance.

Parameters:

Name Type Description Default
langchain_tool Any

LangChain tool implementation to convert.

required

Returns:

Name Type Description
Tool 'Tool'

Tool instance derived from the LangChain representation.

invoke(**kwargs) async

Executes the defined tool with the given parameters.

This method handles both synchronous and asynchronous underlying functions.

Parameters:

Name Type Description Default
**kwargs Any

The parameters to pass to the tool function. These should match the input_schema definition.

{}

Returns:

Name Type Description
Any Any

The result of the tool execution.

Raises:

Type Description
ValueError

If the tool function has not been defined.

TypeError

If the provided parameters don't match the expected schema.

validate_input_schema(v) classmethod

Validate and convert input_schema to JSON Schema dict if it's a Pydantic model.

Parameters:

Name Type Description Default
v Any

The input schema value (dict or Pydantic model).

required

Returns:

Name Type Description
dict

A JSON Schema dict.

Raises:

Type Description
ValueError

If the input schema is not a dict or Pydantic model.

validate_output_schema(v) classmethod

Validate and convert output_schema to JSON Schema dict if it's a Pydantic model.

Parameters:

Name Type Description Default
v Any

The output schema value (dict, Pydantic model, or None).

required

Returns:

Type Description

dict | None: A JSON Schema dict or None.

Raises:

Type Description
ValueError

If the output schema is not None, dict, or Pydantic model.