Data Models#

Malevich Brain uses these data models for its internal operations and for interacting with LLMs and tools.

Messages#

class brain.agents.models.Message(*args: ~typing.Any, created_at: ~datetime.datetime | None = None, updated_at: ~datetime.datetime | None = None, uid: str = <factory>, role: ~typing.Literal['user', 'assistant', 'system'], content: ~typing.List[~brain.agents.models.Content], completed: bool = False, is_intent: bool = False, is_tool_extra_message: bool = False, is_helper_message: bool = False, is_reasoning: bool = False, tool_call_id: str | None = None, **kwargs: ~typing.Any)#

Base message class representing a single interaction in a conversation.

Messages form a linked list to maintain conversation flow, with each message having a role indicating whether it comes from a user, assistant, or system.

Show-inheritance:

model_config: ConfigDict = {'arbitrary_types_allowed': True, 'extra': 'allow', 'ignored_types': (<class 'malevich_ogm.modelling.relation.portal.DefinitionPortal'>,), 'json_schema_extra': {'_malevich_ogm_node': {'label': 'Message', 'name': 'Message', 'relations': []}}}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

role: Literal['user', 'assistant', 'system']#

Identifies the sender of the message. ‘user’ for human messages, ‘assistant’ for AI responses, ‘system’ for configuration instructions.

content: List[Content]#

The main content of the message. Type varies based on message subclass (text, tool calls, etc.).

completed: bool#

Whether the message has been completed.

is_intent: bool#

Whether the message is an intent.

is_tool_extra_message: bool#

Whether the message is a tool extra message.

is_helper_message: bool#

Whether the message is a helper message.

is_reasoning: bool#

Whether the message contains model reasoning content.

tool_call_id: str | None#

If the message is used as a tool call response, this is the ID of the tool call.

add_text_content(text: str, append: bool = False) None#

Add a text content to the message.

get_text_content() str#

Get the text content of the message.

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

q: ClassVar[QStub[Self]] = <malevich_ogm.query.q_class.Q object>#

A filter query stub for the node. Used to build filter queries.

# Filter by name and age
users = await User.search((User.q.name == 'John') & (User.q.age > 30))
sort: ClassVar[SortStub[Self]] = <malevich_ogm.query.sort_class.Sort object>#

A sort query stub for the node. Used to build sort queries.

# Sort by age ascending, then by name descending
users = await User.search(sort=User.q.age | ~User.q.name)
class brain.agents.models.MessageChunk(*, chunk: str, message_uid: str)#

A chunk of a message.

A message chunk is a piece of a message that is sent to the LLM.

Show-inheritance:

model_config: ClassVar[ConfigDict] = {'use_attribute_docstrings': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

chunk: str#

The chunk of the message.

message_uid: str#

The unique identifier of the message that this chunk belongs to.

File Handling#