Module agents.llm.context.items
Classes
class AgentConfigUpdate (**data: Any)-
Expand source code
class AgentConfigUpdate(_ChatItemBase): """Records a mid-conversation change to an agent's instructions or tools. Structural item — excluded from provider conversion; feeds active-config resolution. """ id: str = Field(default_factory=lambda: f"cfgupd_{uuid.uuid4().hex[:12]}") type: Literal["agent_config_update"] = "agent_config_update" instructions: Optional[str] = None tools: Optional[List[str]] = NoneRecords a mid-conversation change to an agent's instructions or tools.
Structural item — excluded from provider conversion; feeds active-config resolution.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- agents.llm.context.items._ChatItemBase
- pydantic.main.BaseModel
Class variables
var id : strvar instructions : str | Nonevar model_configvar tools : List[str] | Nonevar type : Literal['agent_config_update']
class AgentHandoff (**data: Any)-
Expand source code
class AgentHandoff(_ChatItemBase): """Records a transfer of control between agents. Structural item — excluded from provider conversion. """ id: str = Field(default_factory=lambda: f"handoff_{uuid.uuid4().hex[:12]}") type: Literal["agent_handoff"] = "agent_handoff" from_agent: Optional[str] = None to_agent: str reason: Optional[str] = NoneRecords a transfer of control between agents.
Structural item — excluded from provider conversion.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- agents.llm.context.items._ChatItemBase
- pydantic.main.BaseModel
Class variables
var from_agent : str | Nonevar id : strvar model_configvar reason : str | Nonevar to_agent : strvar type : Literal['agent_handoff']
class ChatMessage (**data: Any)-
Expand source code
class ChatMessage(_ChatItemBase): """A user, assistant, system, or developer utterance.""" role: ChatRole content: Union[str, List[ChatContent]] id: str = Field(default_factory=lambda: f"msg_{uuid.uuid4().hex[:12]}") type: Literal["message"] = "message" interrupted: bool = False extra: dict[str, Any] = Field(default_factory=dict) confidence: Optional[float] = None metrics: Optional[dict] = None audio_instructions: Optional[str] = None text_instructions: Optional[str] = None def instructions_for_modality( self, modality: Literal["audio", "text"] ) -> Union[str, List[ChatContent]]: """Return the instruction variant for the given input modality. Falls back to ``content`` when no modality-specific variant is set. """ if modality == "audio" and self.audio_instructions is not None: return self.audio_instructions if modality == "text" and self.text_instructions is not None: return self.text_instructions return self.contentA user, assistant, system, or developer utterance.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- agents.llm.context.items._ChatItemBase
- pydantic.main.BaseModel
Class variables
var audio_instructions : str | Nonevar confidence : float | Nonevar content : str | List[str | ImageContent]var extra : dict[str, typing.Any]var id : strvar interrupted : boolvar metrics : dict | Nonevar model_configvar role : ChatRolevar text_instructions : str | Nonevar type : Literal['message']
Methods
def instructions_for_modality(self, modality: "Literal['audio', 'text']") ‑> str | List[str | ImageContent]-
Expand source code
def instructions_for_modality( self, modality: Literal["audio", "text"] ) -> Union[str, List[ChatContent]]: """Return the instruction variant for the given input modality. Falls back to ``content`` when no modality-specific variant is set. """ if modality == "audio" and self.audio_instructions is not None: return self.audio_instructions if modality == "text" and self.text_instructions is not None: return self.text_instructions return self.contentReturn the instruction variant for the given input modality.
Falls back to
contentwhen no modality-specific variant is set.
class ChatRole (*args, **kwds)-
Expand source code
class ChatRole(str, Enum): """Roles used in chat conversations.""" SYSTEM = "system" DEVELOPER = "developer" USER = "user" ASSISTANT = "assistant"Roles used in chat conversations.
Ancestors
- builtins.str
- enum.Enum
Class variables
var ASSISTANTvar DEVELOPERvar SYSTEMvar USER
class FunctionCall (**data: Any)-
Expand source code
class FunctionCall(_ChatItemBase): """A tool invocation initiated by the language model.""" id: str = Field(default_factory=lambda: f"call_{uuid.uuid4().hex[:12]}") type: Literal["function_call"] = "function_call" name: str arguments: str call_id: str metadata: Optional[dict] = NoneA tool invocation initiated by the language model.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- agents.llm.context.items._ChatItemBase
- pydantic.main.BaseModel
Class variables
var arguments : strvar call_id : strvar id : strvar metadata : dict | Nonevar model_configvar name : strvar type : Literal['function_call']
class FunctionCallOutput (**data: Any)-
Expand source code
class FunctionCallOutput(_ChatItemBase): """The result of a tool execution.""" id: str = Field(default_factory=lambda: f"output_{uuid.uuid4().hex[:12]}") type: Literal["function_call_output"] = "function_call_output" name: str call_id: str output: str is_error: bool = FalseThe result of a tool execution.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- agents.llm.context.items._ChatItemBase
- pydantic.main.BaseModel
Class variables
var call_id : strvar id : strvar is_error : boolvar model_configvar name : strvar output : strvar type : Literal['function_call_output']
class ImageContent (**data: Any)-
Expand source code
class ImageContent(BaseModel): """Image content in a chat message.""" model_config = ConfigDict(arbitrary_types_allowed=True) id: str = Field(default_factory=lambda: f"img_{uuid.uuid4().hex[:12]}") type: Literal["image"] = "image" image: Union[av.VideoFrame, str] inference_detail: Literal["auto", "high", "low"] = "auto" encode_options: EncodeOptions = Field( default_factory=lambda: EncodeOptions( format="JPEG", quality=90, resize_options=ResizeOptions(width=320, height=240), ) ) def to_data_url(self) -> str: """Convert the image to a data URL string.""" if isinstance(self.image, str): return self.image encoded_image = images.encode(self.image, self.encode_options) b64_image = base64.b64encode(encoded_image).decode("utf-8") return f"data:image/{self.encode_options.format.lower()};base64,{b64_image}"Image content in a chat message.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- pydantic.main.BaseModel
Class variables
var encode_options : EncodeOptionsvar id : strvar image : av.video.frame.VideoFrame | strvar inference_detail : Literal['auto', 'high', 'low']var model_configvar type : Literal['image']
Methods
def to_data_url(self) ‑> str-
Expand source code
def to_data_url(self) -> str: """Convert the image to a data URL string.""" if isinstance(self.image, str): return self.image encoded_image = images.encode(self.image, self.encode_options) b64_image = base64.b64encode(encoded_image).decode("utf-8") return f"data:image/{self.encode_options.format.lower()};base64,{b64_image}"Convert the image to a data URL string.