Skip to content

Commit 105e37e

Browse files
author
camel-docs-bot
committed
Auto-update documentation after merge
1 parent b7b0e3f commit 105e37e

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

docs/mintlify/reference/camel.agents.chat_agent.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,21 @@ def update_memory(
254254

255255
Updates the agent memory with a new message.
256256

257+
If the single *message* exceeds the model's context window, it will
258+
be **automatically split into multiple smaller chunks** before being
259+
written into memory. This prevents later failures in
260+
`ScoreBasedContextCreator` where an over-sized message cannot fit
261+
into the available token budget at all.
262+
263+
This slicing logic handles both regular text messages (in the
264+
`content` field) and long tool call results (in the `result` field of
265+
a `FunctionCallingMessage`).
266+
257267
**Parameters:**
258268

259269
- **message** (BaseMessage): The new message to add to the stored messages.
260270
- **role** (OpenAIBackendRole): The backend role type.
261-
- **timestamp** (Optional[float], optional): Custom timestamp for the memory record. If None, current timestamp will be used. (default: :obj:`None`)
271+
- **timestamp** (Optional[float], optional): Custom timestamp for the memory record. If `None`, the current time will be used. (default: :obj:`None`) (default: obj:`None`)
262272

263273
<a id="camel.agents.chat_agent.ChatAgent.load_memory"></a>
264274

docs/mintlify/reference/camel.memories.context_creators.score_based.mdx

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ API compatibility
8383
def _group_tool_calls_and_responses(self, units: List[_ContextUnit]):
8484
```
8585

86-
Groups tool calls with their corresponding responses.
86+
Groups tool calls with their corresponding responses based on
87+
`tool_call_id`.
88+
89+
This improved logic robustly gathers all messages (assistant requests
90+
and tool responses, including chunks) that share a `tool_call_id`.
8791

8892
**Parameters:**
8993

90-
- **units** (List[_ContextUnit]): List of context units to analyze
94+
- **units** (List[_ContextUnit]): List of context units to analyze.
9195

9296
**Returns:**
9397

94-
Dict[str, List[_ContextUnit]]: Mapping from tool_call_id to list of
95-
related units (tool call + responses)
98+
Dict[str, List[_ContextUnit]]: Mapping from `tool_call_id` to a
99+
list of related units.
96100

97101
<a id="camel.memories.context_creators.score_based.ScoreBasedContextCreator._truncate_with_tool_call_awareness"></a>
98102

@@ -108,16 +112,24 @@ def _truncate_with_tool_call_awareness(
108112
```
109113

110114
Truncates messages while preserving tool call-response pairs.
115+
This method implements a more sophisticated truncation strategy:
116+
1. It treats tool call groups (request + responses) and standalone
117+
messages as individual items to be included.
118+
2. It sorts all items by score and greedily adds them to the context.
119+
3. **Partial Truncation**: If a complete tool group is too large to
120+
fit,it attempts to add the request message and as many of the most
121+
recent response chunks as the token budget allows.
111122

112123
**Parameters:**
113124

114-
- **regular_units** (List[_ContextUnit]): All regular message units
115-
- **tool_call_groups** (Dict[str, List[_ContextUnit]]): Grouped tool calls
116-
- **system_tokens** (int): Tokens used by system message
125+
- **regular_units** (List[_ContextUnit]): All regular message units.
126+
- **tool_call_groups** (Dict[str, List[_ContextUnit]]): Grouped tool calls.
127+
- **system_tokens** (int): Tokens used by the system message.
117128

118129
**Returns:**
119130

120-
List[_ContextUnit]: Units that fit within token limit
131+
List[_ContextUnit]: A list of units that fit within the token
132+
limit.
121133

122134
<a id="camel.memories.context_creators.score_based.ScoreBasedContextCreator._extract_system_message"></a>
123135

@@ -141,31 +153,6 @@ Extracts the system message from records and validates it.
141153
- An empty list, serving as the initial container for regular
142154
messages.
143155

144-
<a id="camel.memories.context_creators.score_based.ScoreBasedContextCreator._truncation_sort_key"></a>
145-
146-
### _truncation_sort_key
147-
148-
```python
149-
def _truncation_sort_key(self, unit: _ContextUnit):
150-
```
151-
152-
Defines the sorting key for the truncation phase.
153-
154-
Sorting priority:
155-
- Primary: Sort by score in descending order (higher scores first).
156-
- Secondary: Sort by timestamp in ascending order (older messages
157-
first when scores are equal).
158-
159-
**Parameters:**
160-
161-
- **unit** (_ContextUnit): A `_ContextUnit` representing a conversation record.
162-
163-
**Returns:**
164-
165-
Tuple[float, float]:
166-
- Negative score for descending order sorting.
167-
- Timestamp for ascending order sorting.
168-
169156
<a id="camel.memories.context_creators.score_based.ScoreBasedContextCreator._conversation_sort_key"></a>
170157

171158
### _conversation_sort_key

0 commit comments

Comments
 (0)