Mind Map Module¶
The Mind Map module defines the data structures for representing tasks, messages, and various message parts in the Azad system. It is one of the most critical components as it defines the core data model for the entire agent system.
Overview¶
The Mind Map is a data structure that represents the conversation and tool interactions within a task. It consists of:
- A
Taskclass that contains a list of messages and the current state - Various
Messageclasses for different roles (system, user, assistant, tool) - Various
Partclasses for different content types (text, image, tool call, tool result)
This structure allows the agent to maintain a complete history of the conversation and tool interactions, which is essential for context management and reasoning.
Key Concepts¶
Task Structure¶
The Task class is the root of the Mind Map data structure. It represents a specific task being executed by the agent and contains:
- A list of messages (system, user, assistant, tool)
- The current state of the task (running, completed, failed, etc.)
- Methods for adding and retrieving messages
Message Flow¶
The Mind Map is designed to support a specific message flow:
- The task starts with a
TaskConfigMessagethat defines the configuration for the task - The user sends a
UserMessagewith the task description - The assistant responds with an
AssistantMessagethat may contain text and/or tool calls - If the assistant calls a tool, a
ToolMessageis added with the tool result - This cycle continues until the task is completed
Nested Tasks¶
The Mind Map supports nested tasks, which allow the agent to work on subtasks within a main task. This is implemented through:
TaskEntryMessage: Marks the start of a nested taskTaskExitMessage: Marks the end of a nested taskcurrent_task_level(): Calculates the current nesting levelcurrent_task_messages(): Gets messages within the current task levelcurrent_task_config(): Gets the configuration for the current task level
This nesting capability is essential for complex tasks that require multiple steps or subtasks.
Tool Call Flow¶
Tool calls follow a specific flow:
- Assistant adds a
ToolCallPartto anAssistantMessage - Environment approves or rejects the tool call
- Tool is executed if approved
- Result is added as a
ToolResultPartin aToolMessage
Compression Support¶
The Mind Map supports compression through CompressionMessage, which records which messages were compressed and how.
Important Considerations¶
When working with the Mind Map:
-
Task Boundaries: Always respect task boundaries when processing messages. Use
current_task_messages()instead of accessingtask.messagesdirectly. -
Message Order: Messages are ordered chronologically. The
started_tsandfinished_tsfields track when each message was created and completed. -
Tool Call Flow: Tool calls follow a specific flow as described above.
-
Nested Tasks: Nested tasks allow for complex workflows. Each nested task has its own configuration and message history.
API Reference¶
azad.mind_map ¶
Attributes¶
SystemContent
module-attribute
¶
SystemContent = List[TextPart]
Type alias for the content of a SystemMessage (list of TextParts).
UserContent
module-attribute
¶
Type alias for the content of a UserMessage (list of Text, Image, or FileParts).
AssistantContent
module-attribute
¶
AssistantContent = List[Union[TextPart, ToolCallPart, ReasoningPart, RedactedThinkingPart]]
Type alias for the content of an AssistantMessage (list of Text, ToolCall, Reasoning, or RedactedThinkingParts).
ToolContent
module-attribute
¶
ToolContent = List[ToolResultPart]
Type alias for the content of a ToolMessage (list of ToolResultParts).
InformationalContent
module-attribute
¶
InformationalContent = List[InformationalPart]
Type alias for the content of an InformationalMessage (list of InformationalParts).
CompressionContent
module-attribute
¶
CompressionContent = List[CompressionPart]
Type alias for the content of a CompressionMessage (list of CompressionParts).
TaskConfigContent
module-attribute
¶
TaskConfigContent = List[TaskConfigPart]
Type alias for the content of a TaskConfigMessage (list of TaskConfigParts).
TaskEntryContent
module-attribute
¶
TaskEntryContent = List[TaskEntryPart]
Type alias for the content of a TaskEntryMessage (list of TaskEntryParts).
TaskExitContent
module-attribute
¶
TaskExitContent = List[TaskExitPart]
Type alias for the content of a TaskExitMessage (list of TaskExitParts).
Message
module-attribute
¶
Message = Union[SystemMessage, UserMessage, AssistantMessage, ToolMessage, InformationalMessage, CompressionMessage, TaskConfigMessage, TaskEntryMessage, TaskExitMessage]
Type alias representing any possible message class.
Classes¶
TaskState ¶
Bases: str, Enum
Enum representing the possible states of a task.
Attributes:
-
running–The task is currently executing or awaiting input/action.
-
completed–The task has finished successfully without errors.
-
failed–The task encountered an error and could not complete.
-
paused–The task execution has been temporarily suspended.
-
aborted–The task was explicitly stopped before completion.
-
resume_awaited–The task is paused and waiting for a trigger to resume.
ObserverResult ¶
Bases: BaseModel
Represents the outcome of a single observer monitoring a tool execution.
Observers can perform checks or actions related to a tool's execution (e.g., safety checks, logging, validation).
Attributes:
-
is_success(bool) –Indicates whether the observer's check passed or action succeeded.
-
observer_name(str) –The unique identifier for the observer that produced this result.
-
message(Optional[str]) –An optional human-readable message from the observer (e.g., reason for failure).
-
data(Optional[ANYJSON]) –Optional structured data provided by the observer (e.g., validation details).
TextPart ¶
Bases: BaseModel
Represents a plain text segment within a message's content.
Attributes:
ImagePart ¶
Bases: BaseModel
Represents an image within a message's content.
Attributes:
FilePart ¶
Bases: BaseModel
Represents a file attachment within a message's content (typically User messages).
Attributes:
ReasoningPart ¶
Bases: BaseModel
Represents the reasoning or thinking process of an Assistant, often before generating output or calling a tool.
Attributes:
-
type(Literal['reasoning']) –Always 'reasoning'. Discriminator field for message part unions.
-
reasoning(str) –The textual description of the Assistant's thought process.
-
signature(str | None) –An optional cryptographic signature to verify the origin or integrity of the reasoning, if applicable.
-
started_ts(float | None) –Optional timestamp (Unix epoch seconds) when the reasoning process started.
-
finished_ts(float | None) –Optional timestamp (Unix epoch seconds) when the reasoning process finished.
RedactedThinkingPart ¶
Bases: BaseModel
Represents a placeholder for thinking/reasoning that has been redacted or omitted, possibly for brevity or privacy.
Attributes:
ToolCallPart ¶
Bases: BaseModel
Represents a request from the Assistant to execute a specific tool with given arguments.
This part initiates a tool execution flow. It will typically be followed later
by a ToolMessage containing a ToolResultPart with the same tool_call_id.
Attributes:
-
type(Literal['toolCall']) –Always 'toolCall'. Discriminator field for message part unions.
-
tool_call_id(str) –A unique identifier for this specific tool invocation attempt. Used to link this call to its corresponding
ToolResultPart. -
tool_name(str) –The name of the tool the Assistant wants to execute.
-
args(ANYJSON) –A JSON object (dictionary) containing the arguments for the tool, as generated by the Assistant.
-
is_loading(bool) –Indicates if the tool call is currently being processed (result pending). Starts True, becomes False when the result is added.
-
is_approval_pending(bool) –Indicates if the tool call requires explicit user/system approval before execution. Starts True if auto-approval is off.
ToolResultContent ¶
Bases: BaseModel
Represents a discrete piece of content generated by a tool, intended for display or further processing.
A single ToolResultPart can contain multiple ToolResultContent parts (e.g., text and an image).
Attributes:
-
type(Literal['text'] | Literal['image']) –The type of content, currently 'text' or 'image'.
-
text(Optional[str]) –The textual content generated by the tool (used if type is 'text').
-
image_data(Optional[str]) –The image data generated by the tool, typically base64 (used if type is 'image').
-
mime_type(Optional[str]) –The MIME type if the content is an image (e.g., 'image/png').
ToolResultPart ¶
Bases: BaseModel
Represents the result of executing a tool that was previously requested via a ToolCallPart.
This part concludes a tool execution flow initiated by a ToolCallPart.
Attributes:
-
type(Literal['toolResult']) –Always 'toolResult'. Discriminator field for message part unions.
-
tool_call_id(str) –The unique identifier matching the
tool_call_idof theToolCallPartthat initiated this execution. Links the result back to the request. -
tool_name(str) –The name of the tool that was executed.
-
result(ANYJSON) –The primary result data from the tool execution, typically a JSON object. The structure depends on the specific tool.
-
observer_results(List[ObserverResult]) –A list of
ObserverResultobjects, capturing outcomes from any observers that monitored this tool execution. -
is_approved(bool) –Indicates whether the execution of this tool call was approved (either automatically or manually).
-
is_error(bool) –Indicates whether the tool execution resulted in an error.
-
error(str | None) –A description of the error if
is_erroris True. -
is_loading(bool) –Indicates if the result itself is still loading (rarely True, usually False when part is added).
-
has_feedback(bool) –Indicates if feedback has been provided for this tool result (e.g., by the user).
-
tool_result_contents(List[ToolResultContent]) –A list of
ToolResultContentparts representing displayable output generated by the tool (e.g., text summaries, images).
Attributes¶
observer_results
class-attribute
instance-attribute
¶
observer_results: List[ObserverResult] = Field(default_factory=list)
tool_result_contents
class-attribute
instance-attribute
¶
tool_result_contents: List[ToolResultContent] = Field(default_factory=list)
InformationalPart ¶
Bases: BaseModel
Represents metadata or non-core conversational events within a message.
Used for conveying system status, errors unrelated to specific tool calls, or other contextual information that isn't direct user/assistant dialogue.
Attributes:
-
type(Literal['informational']) –Always 'informational'. Discriminator field for message part unions.
-
is_visible_ai(bool) –Whether this information should be considered by the AI/Assistant.
-
is_visible_ui(bool) –Whether this information should typically be displayed to the end-user.
-
informational_type(Optional[str]) –A category for the information (e.g., 'system_status', 'context_update', 'error').
-
error_type(Optional[str]) –If it's an error, a more specific error category.
-
details(Optional[str]) –A human-readable description of the information or event.
-
additional_data(Optional[ANYJSON] | Optional[List[ANYJSON]]) –Optional structured data associated with the event.
CompressionPart ¶
Bases: BaseModel
Contains metadata about a message compression event that occurred in the conversation history.
This part doesn't represent conversational content itself, but rather describes an operation performed on previous messages.
Attributes:
-
type(Literal['compression']) –Always 'compression'. Discriminator field for message part unions.
-
start_message_idx(int) –The starting index (in the original message list) of the compressed range.
-
end_message_idx(int) –The ending index (inclusive) of the compressed range.
-
reason(str) –The reason why compression was applied (e.g., 'token_limit', 'summarization').
-
strategies(List[str]) –A list of strategies used for compression (e.g., 'summarize', 'drop_intermediate').
-
compressed_message_ids(List[str]) –List of message IDs that were removed or replaced during compression.
-
kept_message_ids(List[str]) –List of message IDs within the range that were retained (if any).
-
cache(Dict[str, Any]) –A dictionary possibly containing cached data related to the compression (e.g., the summary).
-
metadata(Optional[Dict[str, Any]]) –Optional dictionary for any other relevant metadata about the compression event.
TaskConfigPart ¶
Bases: BaseModel
Represents the configuration settings for a task or sub-task.
This defines parameters like the AI model, tools available, prompt segments, etc.
Attributes:
-
type(Literal['taskconfig']) –Always 'taskconfig'. Discriminator field for message part unions.
-
model_name(str) –Identifier for the primary language model to be used.
-
max_tokens(int | None) –Optional maximum allowed number of tokens to generate.
-
dialect_name(str | None) –Optional name of the prompt dialect/formatter to use.
-
dialect_options(dict[str, Any] | None) –Optional dictionary of options specific to the chosen dialect.
-
user_agent_prompt(str | None) –Optional prompt segment defining the user agent's behavior or persona.
-
user_prompt(str | None) –Optional prompt segment providing user-specific instructions or context.
-
thinking_budget_tokens(int | None) –Optional limit on tokens the Assistant can use for internal 'thinking' steps.
-
tool_metadata(List[ToolMetadata]) –List of
ToolMetadataobjects describing the tools available in this task context. -
enable_parallel_tools(bool) –Whether the Assistant is allowed to request multiple tool calls concurrently.
-
enable_auto_tools(bool) –Whether tool calls should be executed automatically without explicit approval.
-
compression_config(CompressionConfig) –Configuration for message history compression behavior.
Attributes¶
max_tokens
class-attribute
instance-attribute
¶
max_tokens: int | None = Field(None, description='Optional maximum allowed number of tokens to generate')
user_agent_prompt
class-attribute
instance-attribute
¶
user_agent_prompt: str | None = Field(None, description='Optional prompt section for user agent configuration')
tool_metadata
class-attribute
instance-attribute
¶
tool_metadata: List[ToolMetadata] = Field(default_factory=list)
enable_parallel_tools
class-attribute
instance-attribute
¶
enable_parallel_tools: bool = Field(default=True, description='Whether to enable parallel tool calls')
enable_auto_tools
class-attribute
instance-attribute
¶
enable_auto_tools: bool = Field(default=False, description='Whether tools should be automatically approved')
compression_config
class-attribute
instance-attribute
¶
compression_config: CompressionConfig = Field(default=CompressionConfig(enabled=True, token_limit=200000), description='Configuration for message history compression')
enable_search
class-attribute
instance-attribute
¶
enable_search: bool = Field(False, description='Whether to enable search/grounding via Gemini built-in tools.')
TaskEntryPart ¶
Bases: BaseModel
Marks the beginning of a nested sub-task within the main task flow.
Typically created when a tool call indicates the start of a sub-problem.
Attributes:
-
type(Literal['taskentry']) –Always 'taskentry'. Discriminator field for message part unions.
-
initial_task_config(TaskConfigPart) –The
TaskConfigPartdefining the configuration for this specific sub-task. -
initial_context(List[InformationalPart | TextPart | ImagePart]) –A list of
TextPart,ImagePart, orInformationalPartproviding the initial context or description given to this sub-task.
Attributes¶
initial_context
class-attribute
instance-attribute
¶
initial_context: List[InformationalPart | TextPart | ImagePart] = Field(default_factory=list)
TaskExitPart ¶
Bases: BaseModel
Marks the end of a nested sub-task, providing results back to the parent task.
This usually corresponds to the completion of a sub-task initiated by a TaskEntryPart.
Attributes:
-
type(Literal['taskexit']) –Always 'taskexit'. Discriminator field for message part unions.
-
handoff_description(List[TextPart | ImagePart]) –A list of
TextPartorImagePartdescribing the results or outcome of the sub-task, intended for the parent task's context (often used to populate the result of the tool call that triggered the sub-task).
MessageRole ¶
Bases: str, Enum
Enumeration of the possible roles a message can have in the conversation.
Attributes:
-
system–Instructions or context provided by the system, not a direct participant.
-
user–Input provided by the end-user.
-
assistant–Responses or actions generated by the AI model.
-
tool–Results returned from executing a tool requested by the assistant.
-
informational–Metadata, status updates, or non-dialogue events.
-
compression–Metadata about message history compression events.
-
taskconfig–Contains configuration settings for the current task scope.
-
taskentry–Marks the beginning of a nested sub-task.
-
taskexit–Marks the end of a nested sub-task.
MessageBase ¶
Bases: BaseModel
Base model for all message types, containing common metadata fields.
Attributes:
-
id(str) –A unique identifier for this specific message instance (default: generated nanoid).
-
task_id(str) –The identifier of the parent Task this message belongs to.
-
started_ts(int) –Timestamp (Unix epoch seconds) when the message was created or started processing.
-
finished_ts(int | None) –Optional timestamp (Unix epoch seconds) when the message processing completed (e.g., Assistant response finished, tool result received).
-
world_state_id(str | None) –Optional identifier for the world state snapshot associated with this message.
-
world_state_hash(str | None) –Optional hash representing the world state at the time of this message.
-
error_message(str | None) –Optional error message if the creation or processing of this message failed.
SystemMessage ¶
Bases: MessageBase
A message containing system-level instructions or context.
Attributes:
-
role(Literal[system]) –Always 'system'.
-
content(SystemContent) –A list containing only
TextPartelements.
UserMessage ¶
Bases: MessageBase
A message representing input from the end-user.
Attributes:
-
role(Literal[user]) –Always 'user'.
-
content(UserContent) –A list containing
TextPart,ImagePart, orFilePartelements. -
is_ui_hidden(Optional[bool]) –If True, suggests this message might not be directly displayed in a standard chat UI (e.g., could be programmatically added context).
AssistantMessage ¶
Bases: MessageBase
A message representing output or actions from the AI Assistant.
Attributes:
-
role(Literal[assistant]) –Always 'assistant'.
-
content(AssistantContent) –A list containing
TextPart,ToolCallPart,ReasoningPart, orRedactedThinkingPartelements. -
status(Literal['loading', 'completed', 'error', 'interrupted']) –The current status of the Assistant's turn generation ('loading', 'completed', 'error', 'interrupted').
-
cost(float | None) –Optional cost associated with generating this message (e.g., API cost).
-
cache_writes(int | None) –Optional count of cache writes during generation.
-
cache_reads(int | None) –Optional count of cache reads during generation.
-
tokens_in(int | None) –Optional count of input tokens processed to generate this message.
-
tokens_out(int | None) –Optional count of output tokens generated in this message.
-
model_id(str | None) –Optional identifier of the language model used to generate this message.
Attributes¶
content
class-attribute
instance-attribute
¶
content: AssistantContent = Field(default_factory=list)
ToolMessage ¶
Bases: MessageBase
A message containing the results of tool executions requested by the Assistant.
Attributes:
-
role(Literal[tool]) –Always 'tool'.
-
content(ToolContent) –A list containing only
ToolResultPartelements, each corresponding to a previously issuedToolCallPart.
InformationalMessage ¶
Bases: MessageBase
A message conveying metadata, status, or non-dialogue events.
Attributes:
-
role(Literal[informational]) –Always 'informational'.
-
content(InformationalContent) –A list containing only
InformationalPartelements.
Attributes¶
role
class-attribute
instance-attribute
¶
role: Literal[informational] = Field(default=informational)
content
class-attribute
instance-attribute
¶
content: InformationalContent = Field(default_factory=list)
CompressionMessage ¶
Bases: MessageBase
A message containing metadata about a message history compression event.
Attributes:
-
role(Literal[compression]) –Always 'compression'.
-
content(CompressionContent) –A list containing only
CompressionPartelements.
Attributes¶
content
class-attribute
instance-attribute
¶
content: CompressionContent = Field(default_factory=list)
TaskConfigMessage ¶
Bases: MessageBase
A message containing configuration settings applicable to the current task scope.
Attributes:
-
role(Literal[taskconfig]) –Always 'taskconfig'.
-
content(TaskConfigContent) –A list containing only
TaskConfigPartelements.
Attributes¶
content
class-attribute
instance-attribute
¶
content: TaskConfigContent = Field(default_factory=list)
TaskEntryMessage ¶
Bases: MessageBase
A message marking the beginning of a nested sub-task.
Attributes:
-
role(Literal[taskentry]) –Always 'taskentry'.
-
content(TaskEntryContent) –A list containing only
TaskEntryPartelements.
Attributes¶
content
class-attribute
instance-attribute
¶
content: TaskEntryContent = Field(default_factory=list)
TaskExitMessage ¶
Bases: MessageBase
A message marking the end of a nested sub-task.
Attributes:
-
role(Literal[taskexit]) –Always 'taskexit'.
-
content(TaskExitContent) –A list containing only
TaskExitPartelements.
Task ¶
Bases: BaseModel
Represents a single, self-contained task or conversation.
Manages the state, overall content (like a title or summary), and the chronological list of messages that make up the task's history. Includes methods for manipulating and querying the message list and task state.
Attributes:
-
id(str) –Unique identifier for the task (default: generated nanoid).
-
state(TaskState) –The current
TaskStateof the task. -
content(List[ImagePart | TextPart]) –High-level content describing the task itself (e.g., title, summary), represented as a list of Text or Image parts.
-
messages(List[Message]) –The chronological list of
Messageobjects comprising the task history.
Attributes¶
Functions¶
validate_messages
classmethod
¶
Pydantic validator (before initialization) to ensure messages in the input
data are converted to their appropriate Message subclasses based on 'role'.
Parameters:
-
data(Dict[str, Any]) –The raw dictionary data attempting to be validated into a Task model.
Returns:
-
Dict[str, Any]–The dictionary data with the 'messages' list potentially transformed
-
Dict[str, Any]–to contain proper Message model instances.
Raises:
-
ValueError–If a message dictionary has an unknown 'role' or fails validation.
-
(Note–Current implementation logs warnings/errors instead of raising)
Source code in azad/mind_map.py
current_task_level ¶
Calculates the current nesting level based on TaskEntry and TaskExit messages.
Level 0 represents the root task. Each TaskEntry increments the level, and each TaskExit decrements it.
Returns:
-
int–The current nesting depth (0 for root, 1 for the first sub-task, etc.).
Source code in azad/mind_map.py
current_task_config ¶
current_task_config() -> TaskConfigPart
Gets the TaskConfigPart that applies to the current task nesting level.
For nested tasks (level > 0), it retrieves the config from the corresponding
TaskEntryMessage. For the root level (level 0), it finds the most recent
TaskConfigMessage at that level.
Returns:
-
TaskConfigPart–The applicable
TaskConfigPart.
Raises:
-
ValueError–If no applicable configuration can be found (should not happen in a well-formed task).
Source code in azad/mind_map.py
current_task_messages ¶
current_task_messages() -> List[Message]
Retrieves all messages belonging to the current active task nesting level.
Includes the TaskEntry and TaskExit messages that define the boundaries of the current level.
Returns:
-
List[Message]–A list of
Messageobjects within the current task scope.
Source code in azad/mind_map.py
find_current_task_boundaries ¶
Finds the indices of the TaskEntry and TaskExit messages for the current level.
Returns:
-
Optional[int]–A tuple
(start_index, end_index): -
Optional[int]–start_index: Index of theTaskEntryMessagefor the current level (or 0 if at root level) None if level > 0 and not found.
-
Tuple[Optional[int], Optional[int]]–end_index: Index of the correspondingTaskExitMessage, orNoneif the task level has not yet exited.
-
Tuple[Optional[int], Optional[int]]–Returns
(0, None)for root level.
Source code in azad/mind_map.py
add_task_entry ¶
add_task_entry(task_description: Sequence[Union[TextPart, ImagePart, InformationalPart]], initial_task_config: TaskConfigPart) -> TaskEntryMessage
Initiates a new nested task level by adding required messages.
Sequence of messages added:
1. TaskEntryMessage: Contains the initial context and config reference.
2. TaskConfigMessage: The actual configuration for the new task level.
3. UserMessage (hidden): Contains text/image parts from the initial context.
4. InformationalMessage(s): One for each informational part in the initial context.
Parameters:
-
task_description(Sequence[Union[TextPart, ImagePart, InformationalPart]]) –A sequence of parts describing the sub-task's goal or initial state.
-
initial_task_config(TaskConfigPart) –The configuration (
TaskConfigPart) for this new sub-task.
Returns:
-
TaskEntryMessage–The created
TaskEntryMessage.
Source code in azad/mind_map.py
add_task_exit ¶
add_task_exit(handoff_description: Sequence[Union[TextPart, ImagePart]], payloadKey='task_result') -> Tuple[TaskExitMessage, Optional[ToolMessage]]
Completes the current nested task level and potentially updates the triggering tool result.
Adds a TaskExitMessage and attempts to find the ToolCallPart (usually in the
parent level's AssistantMessage) that initiated this sub-task. If found, it
updates the corresponding ToolResultPart (or adds a new ToolMessage) with
the handoff_description.
Parameters:
-
handoff_description(Sequence[Union[TextPart, ImagePart]]) –Sequence of Text/Image parts describing the sub-task's outcome.
-
payloadKey–The key within the tool result's
resultdictionary where the text handoff description will be stored.
Returns:
-
TaskExitMessage–A tuple containing:
-
Optional[ToolMessage]–- The newly created
TaskExitMessage.
- The newly created
-
Tuple[TaskExitMessage, Optional[ToolMessage]]–- The
ToolMessagethat was updated or created with the result (orNoneif the triggering tool call could not be reliably identified).
- The
Source code in azad/mind_map.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | |
get_message ¶
get_message(message_id: str) -> Optional[Message]
Retrieves a message from the task history by its unique ID.
Parameters:
-
message_id(str) –The ID of the message to retrieve.
Returns:
-
Optional[Message]–The
Messageobject if found, otherwiseNone.
Source code in azad/mind_map.py
get_current_config ¶
get_current_config() -> TaskConfigPart
Gets the most recently added TaskConfigPart from the entire message history.
Searches backwards through all messages. This is a fallback or general-purpose
config retrieval method. Use current_task_config for level-specific config.
Returns:
-
TaskConfigPart–The last found
TaskConfigPart.
Raises:
-
ValueError–If no
TaskConfigMessageexists anywhere in the history.
Source code in azad/mind_map.py
add_task_config ¶
add_task_config(part: TaskConfigPart, timestamp: Optional[float] = None) -> TaskConfigMessage
Adds a new TaskConfigMessage to the history.
Parameters:
-
part(TaskConfigPart) –The
TaskConfigPartcontaining the configuration settings. -
timestamp(Optional[float], default:None) –Optional timestamp (Unix epoch float) for the message creation. Defaults to now.
Returns:
-
TaskConfigMessage–The newly created
TaskConfigMessage.
Source code in azad/mind_map.py
add_human_message ¶
add_human_message(text: Optional[Union[str, List[str]]] = None, images: Optional[List[ImagePart]] = None, is_ui_hidden: bool = False, timestamp: Optional[float] = None) -> Optional[UserMessage]
Adds a new UserMessage to the history.
Parameters:
-
text(Optional[Union[str, List[str]]], default:None) –A single string or list of strings for text content.
-
images(Optional[List[ImagePart]], default:None) –A list of
ImagePartobjects for image content. -
is_ui_hidden(bool, default:False) –Whether to mark the message as potentially hidden in the UI.
-
timestamp(Optional[float], default:None) –Optional timestamp (Unix epoch float) for message creation. Defaults to now.
Returns:
-
Optional[UserMessage]–The newly created
UserMessageif it has content, otherwiseNone.
Source code in azad/mind_map.py
add_message ¶
add_message(message: Message)
Appends a message to the task's history list and updates timestamps.
Sets the finished_ts of the previous message to the started_ts
of the new message (or current time, whichever is earlier, but not before
the previous message's start time). Also ensures the new message has
task_id and started_ts set.
Parameters:
-
message(Message) –The
Messageobject to add.
Source code in azad/mind_map.py
add_informational_message ¶
add_informational_message(informational_type: str, details: str, is_visible_ai: bool = False, is_visible_ui: bool = False, additional_data: Optional[ANYJSON] | Optional[List[ANYJSON]] = None, timestamp: Optional[float] = None) -> InformationalMessage
Adds a new InformationalMessage to the history.
Parameters:
-
informational_type(str) –Category of the information.
-
details(str) –Human-readable details.
-
is_visible_ai(bool, default:False) –Should the AI see this?
-
is_visible_ui(bool, default:False) –Should the UI display this?
-
additional_data(Optional[ANYJSON] | Optional[List[ANYJSON]], default:None) –Optional structured data.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
InformationalMessage–The newly created
InformationalMessage.
Source code in azad/mind_map.py
add_text_part ¶
Appends a TextPart to the content of an existing message.
Only applicable to messages whose content list supports TextPart
(System, User, Assistant).
Parameters:
-
message_id(str) –The ID of the message to modify.
-
text(str) –The text content to add.
Returns:
-
bool–Trueif the part was added successfully,Falseotherwise (e.g., message -
bool–not found, wrong role, content not a list).
Source code in azad/mind_map.py
add_reasoning_part ¶
Appends a ReasoningPart to the content of an existing AssistantMessage.
Parameters:
-
message_id(str) –The ID of the
AssistantMessageto modify. -
reasoning(str) –The reasoning text.
-
signature(Optional[str]) –Optional signature for the reasoning.
Returns:
-
bool–Trueif the part was added successfully,Falseotherwise.
Source code in azad/mind_map.py
add_tool_call_part ¶
add_tool_call_part(message_id: str, tool_call: ToolCallPart) -> bool
Appends a ToolCallPart to the content of an existing AssistantMessage.
Also sets the AssistantMessage status back to 'loading' if it was 'completed'.
Parameters:
-
message_id(str) –The ID of the
AssistantMessageto modify. -
tool_call(ToolCallPart) –The
ToolCallPartobject to add.
Returns:
-
bool–Trueif the part was added successfully,Falseotherwise.
Source code in azad/mind_map.py
add_assistant_message ¶
add_assistant_message(id: Optional[str] = None, timestamp: Optional[float] = None) -> AssistantMessage
Adds a new, empty AssistantMessage to the history, ready to be populated.
Sets the initial status to 'loading' and fetches the model name from the current task configuration.
Parameters:
-
id(Optional[str], default:None) –Optional specific ID for the message. If None, a nanoid is generated.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
AssistantMessage–The newly created
AssistantMessage.
Raises:
-
ValueError–If the current task configuration cannot be determined.
Source code in azad/mind_map.py
add_system_message ¶
add_system_message(text: str, id: Optional[str] = None, timestamp: Optional[float] = None) -> SystemMessage
Adds a new SystemMessage with the given text content.
Parameters:
-
text(str) –The text content for the system message.
-
id(Optional[str], default:None) –Optional specific ID for the message. If None, a nanoid is generated.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
SystemMessage–The newly created
SystemMessage.
Source code in azad/mind_map.py
add_tool_result_message ¶
add_tool_result_message(tool_call_id: str, tool_name: str, result: ANYJSON, observer_results: List[ObserverResult], is_error: bool, is_approved: bool, tool_result_contents: List[ToolResultContent] = [], error_message: Optional[str] = None, is_loading: bool = False, has_feedback: bool = False, timestamp: Optional[float] = None) -> ToolMessage
Creates and adds a new ToolMessage containing a single ToolResultPart.
This is the standard way to record a tool's execution result.
Parameters:
-
tool_call_id(str) –The ID of the
ToolCallPartthis result corresponds to. -
tool_name(str) –The name of the tool that was executed.
-
result(ANYJSON) –The primary JSON result data from the tool.
-
observer_results(List[ObserverResult]) –List of results from observers monitoring the execution.
-
is_error(bool) –Boolean indicating if the tool execution failed.
-
is_approved(bool) –Boolean indicating if the tool execution was approved.
-
tool_result_contents(List[ToolResultContent], default:[]) –Optional list of displayable content parts (text/image) generated by the tool.
-
error_message(Optional[str], default:None) –Optional error description if
is_erroris True. -
is_loading(bool, default:False) –Should typically be False when adding the result.
-
has_feedback(bool, default:False) –Optional flag indicating if user feedback exists for this result.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
ToolMessage–The newly created
ToolMessage.
Source code in azad/mind_map.py
add_compression_message ¶
add_compression_message(start_idx: int, end_idx: int, reason: str, strategies: List[str], compressed_message_ids: List[str], kept_message_ids: List[str], cache: Dict[str, Any] = {}, metadata: Optional[Dict[str, Any]] = None, timestamp: Optional[float] = None) -> CompressionMessage
Adds a CompressionMessage to record a history compression event.
Parameters:
-
start_idx(int) –Start index of the compressed message range (original list).
-
end_idx(int) –End index of the compressed message range (original list, inclusive).
-
reason(str) –Reason for compression (e.g., 'token_limit').
-
strategies(List[str]) –List of compression strategies applied.
-
compressed_message_ids(List[str]) –IDs of messages removed/replaced.
-
kept_message_ids(List[str]) –IDs of messages within the range that were kept.
-
cache(Dict[str, Any], default:{}) –Optional cached data related to the compression (e.g., summary).
-
metadata(Optional[Dict[str, Any]], default:None) –Optional additional metadata.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
CompressionMessage–The newly created
CompressionMessage.
Source code in azad/mind_map.py
answer_tool_call ¶
answer_tool_call(tool_call: ToolCallPart, result: ANYJSON, observer_results: List[ObserverResult], is_error: bool, is_approved: bool, tool_result_contents: List[ToolResultContent] = [], error_message: Optional[str] = None, is_loading: bool = False, has_feedback: bool = False, timestamp: Optional[float] = None) -> ToolMessage
Convenience method to add a tool result and update the original call part's status.
Finds the AssistantMessage containing the tool_call and updates the
is_loading and is_approval_pending flags on the ToolCallPart within it.
Then, calls add_tool_result_message to add the actual result.
Parameters:
-
tool_call(ToolCallPart) –The original
ToolCallPartobject that is being answered. -
result(ANYJSON) –The primary JSON result data from the tool.
-
observer_results(List[ObserverResult]) –List of results from observers.
-
is_error(bool) –Boolean indicating if the execution failed.
-
is_approved(bool) –Boolean indicating if the execution was approved.
-
tool_result_contents(List[ToolResultContent], default:[]) –Optional list of displayable content parts from the tool.
-
error_message(Optional[str], default:None) –Optional error description if
is_erroris True. -
is_loading(bool, default:False) –Status for the result itself (usually False).
-
has_feedback(bool, default:False) –Optional flag indicating if user feedback exists.
-
timestamp(Optional[float], default:None) –Optional creation timestamp (Unix epoch float). Defaults to now.
Returns:
-
ToolMessage–The newly created
ToolMessagecontaining the result.
Raises:
-
TypeError–If the
tool_callargument is not aToolCallPartinstance. -
ValueError–If the original
ToolCallPartcannot be found in the history.
Source code in azad/mind_map.py
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 | |
get_updates ¶
get_updates(since_message_id: Optional[str]) -> List[Message]
Retrieves all messages added to the history after a specified message ID.
Parameters:
-
since_message_id(Optional[str]) –The ID of the message after which to retrieve updates. If
Noneor empty, returns all messages in the task.
Returns:
-
List[Message]–A list of
Messageobjects added after the message withsince_message_id. -
List[Message]–Returns all messages if
since_message_idis None or not found.
Source code in azad/mind_map.py
Functions¶
create_message_from_dict ¶
create_message_from_dict(data: Dict[str, Any]) -> Message
Creates the appropriate Message subclass instance from a dictionary.
Uses the 'role' field in the dictionary to determine which message class
(e.g., UserMessage, AssistantMessage) to instantiate and validate against.
Parameters:
-
data(Dict[str, Any]) –A dictionary containing message data, including a 'role' key.
Returns:
-
Message–An instance of the corresponding
Messagesubclass.
Raises:
-
ValueError–If the 'role' key is missing, unknown, or if the data fails validation against the determined message class.