agentle.agents.context

Context management module for Agentle agents.

This module provides the Context class, which serves as a container for all contextual information needed during an agent’s execution. Context represents the conversational state and execution history that an agent uses to generate appropriate responses.

The context includes both the message history (the conversation between user and agent) and execution steps (a record of actions taken by the agent during processing).

Example: ```python from agentle.agents.context import Context from agentle.generations.models.messages.user_message import UserMessage from agentle.generations.models.messages.assistant_message import AssistantMessage from agentle.generations.models.message_parts.text import TextPart

# Create a simple conversation context context = Context(

message_history=[

UserMessage(parts=[TextPart(text=”Hello, can you help me with weather information?”)]), AssistantMessage(parts=[TextPart(text=”Of course! What location would you like weather for?”)])

]

)

# Context can be passed directly to an agent response = agent.run(context)

# Or extended with new messages context.add_user_message(“What’s the weather in New York?”) ```

Functions

Field()

!!! abstract "Usage Documentation"

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

AssistantMessage(*[, role])

Represents a message from an assistant in the system.

BaseModel()

Alias for pydantic.BaseModel.

Context(*[, context_id, message_history, ...])

Container for contextual information that guides an agent's behavior.

DeveloperMessage(*[, role])

Represents a message from a developer in the system.

ExecutionState(*[, state, ...])

Tracks the execution state of an agent context.

MutableMapping()

A MutableMapping is a generic container for associating key/value pairs.

MutableSequence()

All the operations on a read-write sequence.

Sequence()

All the operations on a read-only sequence.

Step(*[, step_id, step_type, timestamp, ...])

Represents a single execution step in an agent's reasoning process.

TextPart(*[, type])

Represents a plain text part of a message.

ToolExecutionResult(*[, type, ...])

Represents the result of a tool execution within a step.

Usage(*[, prompt_tokens, completion_tokens])

Tracks and calculates token consumption in AI model interactions.

UserMessage(*[, role])

Represents a message from a user in the system.

datetime(year, month, day[, hour[, minute[, ...)

The year, month and day arguments are required.