feat: add context overflow detection and automatic history shrinking in agent loop
Implement context manager integration that detects API errors indicating context length exceeded, then automatically shrinks message history and retries the request. Add new messages API functions (remove_range, get_object, replace_at) and a new R_ERROR_CONTEXT_TOO_LONG error code to support this functionality.
This commit is contained in:
@@ -21,11 +21,15 @@ r_status_t messages_add_tool_call(messages_handle msgs, struct json_object *mess
|
||||
r_status_t messages_add_tool_result(messages_handle msgs, const char *tool_call_id, const char *result);
|
||||
|
||||
r_status_t messages_remove_last(messages_handle msgs);
|
||||
r_status_t messages_remove_range(messages_handle msgs, int start, int count);
|
||||
r_status_t messages_clear(messages_handle msgs);
|
||||
|
||||
r_status_t messages_save(messages_handle msgs);
|
||||
r_status_t messages_load(messages_handle msgs);
|
||||
|
||||
struct json_object *messages_get_object(messages_handle msgs, int index);
|
||||
r_status_t messages_replace_at(messages_handle msgs, int index, struct json_object *message);
|
||||
|
||||
struct json_object *messages_to_json(messages_handle msgs);
|
||||
char *messages_to_string(messages_handle msgs);
|
||||
int messages_count(messages_handle msgs);
|
||||
|
||||
@@ -23,6 +23,7 @@ typedef enum {
|
||||
R_ERROR_TOOL_EXECUTION,
|
||||
R_ERROR_API_KEY_MISSING,
|
||||
R_ERROR_API_ERROR,
|
||||
R_ERROR_CONTEXT_TOO_LONG,
|
||||
R_ERROR_MAX_ITERATIONS,
|
||||
R_ERROR_SESSION_INVALID,
|
||||
R_ERROR_UNKNOWN
|
||||
|
||||
Reference in New Issue
Block a user