feat: various performance patches for gpt-5 [LET-4157] (#4381)

* feat: increase the verbosity of the heartbeat kwarg

* chore: strip docstrings out from the file in which they are not parsed (duplicates inside base.py

* feat: add examples to the docstrings for memory_replace and memory_insert

* feat: add more examples
This commit is contained in:
Charles Packer
2025-09-06 11:23:13 -07:00
committed by GitHub
parent 326f9a5049
commit 388dd46ffc
3 changed files with 33 additions and 124 deletions

View File

@@ -223,6 +223,25 @@ def memory_replace(agent_state: "AgentState", label: str, old_str: str, new_str:
old_str (str): The text to replace (must match exactly, including whitespace and indentation).
new_str (str): The new text to insert in place of the old text. Do not include line number prefixes.
Examples:
# Update a block containing information about the user
memory_replace(label="human", old_str="Their name is Alice", new_str="Their name is Bob")
# Update a block containing a todo list
memory_replace(label="todos", old_str="- [ ] Step 5: Search the web", new_str="- [x] Step 5: Search the web")
# Pass an empty string to
memory_replace(label="human", old_str="Their name is Alice", new_str="")
# Bad example - do NOT add (view-only) line numbers to the args
memory_replace(label="human", old_str="Line 1: Their name is Alice", new_str="Line 1: Their name is Bob")
# Bad example - do NOT include the number number warning either
memory_replace(label="human", old_str="# NOTE: Line numbers shown below are to help during editing. Do NOT include line number prefixes in your memory edit tool calls.\\nLine 1: Their name is Alice", new_str="Line 1: Their name is Bob")
# Good example - no line numbers or line number warning (they are view-only), just the text
memory_replace(label="human", old_str="Their name is Alice", new_str="Their name is Bob")
Returns:
str: The success message
"""
@@ -263,11 +282,11 @@ def memory_replace(agent_state: "AgentState", label: str, old_str: str, new_str:
agent_state.memory.update_block_value(label=label, value=new_value)
# Create a snippet of the edited section
SNIPPET_LINES = 3
replacement_line = current_value.split(old_str)[0].count("\n")
start_line = max(0, replacement_line - SNIPPET_LINES)
end_line = replacement_line + SNIPPET_LINES + new_str.count("\n")
snippet = "\n".join(new_value.split("\n")[start_line : end_line + 1])
# SNIPPET_LINES = 3
# replacement_line = current_value.split(old_str)[0].count("\n")
# start_line = max(0, replacement_line - SNIPPET_LINES)
# end_line = replacement_line + SNIPPET_LINES + new_str.count("\n")
# snippet = "\n".join(new_value.split("\n")[start_line : end_line + 1])
# Prepare the success message
success_msg = f"The core memory block with label `{label}` has been edited. "
@@ -290,6 +309,13 @@ def memory_insert(agent_state: "AgentState", label: str, new_str: str, insert_li
new_str (str): The text to insert. Do not include line number prefixes.
insert_line (int): The line number after which to insert the text (0 for beginning of file). Defaults to -1 (end of the file).
Examples:
# Update a block containing information about the user (append to the end of the block)
memory_insert(label="customer", new_str="The customer's ticket number is 12345")
# Update a block containing information about the user (insert at the beginning of the block)
memory_insert(label="customer", new_str="The customer's ticket number is 12345", insert_line=0)
Returns:
Optional[str]: None is always returned as this function does not produce a response.
"""
@@ -328,7 +354,7 @@ def memory_insert(agent_state: "AgentState", label: str, new_str: str, insert_li
# Collate into the new value to update
new_value = "\n".join(new_value_lines)
snippet = "\n".join(snippet_lines)
# snippet = "\n".join(snippet_lines)
# Write into the block
agent_state.memory.update_block_value(label=label, value=new_value)