mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
Add observation-only model request lifecycle hooks (#55144)
## What changed - Add `PreModelRequest` and `PostModelRequest` hooks around model request attempts, including retries. Pass model, session, turn, and optional subagent context; report completion, failure, or cancellation with errors and token usage when available. - Treat hook output as diagnostic data without allowing it to veto requests or alter model context. Wait for synchronous post-request hooks before dispatching tools, while asynchronous hooks allow streaming tool dispatch to continue. - Apply memory-consolidation hook filtering and expose the new events through configuration, protocol schemas, generated clients, and the hooks browser. ## Testing Add integration coverage for failures and retries, ignored control directives, cancellation, synchronous and asynchronous tool ordering, interrupted-turn resume and token accounting, and memory-consolidation filtering. Update hook schema fixtures and hooks browser snapshots. GitOrigin-RevId: 6ed7b39fc8bb94cf467e350d07d97fcc729c21ce
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"AbsolutePathBuf": {
|
||||
"description": "A path that is guaranteed to be absolute and normalized (though it is not guaranteed to be canonicalized or exist on the filesystem).\n\nIMPORTANT: When deserializing an `AbsolutePathBuf`, a base path must be set using [AbsolutePathBufGuard::new]. If no base path is set, the deserialization will fail unless the path being deserialized is already absolute.",
|
||||
"type": "string"
|
||||
},
|
||||
"ModelRequestStatus": {
|
||||
"enum": [
|
||||
"completed",
|
||||
"failed",
|
||||
"cancelled"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"NullableString": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"TokenUsage": {
|
||||
"properties": {
|
||||
"cache_write_input_tokens": {
|
||||
"default": 0,
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"cached_input_tokens": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"input_tokens": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"output_tokens": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"reasoning_output_tokens": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"total_tokens": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"cached_input_tokens",
|
||||
"input_tokens",
|
||||
"output_tokens",
|
||||
"reasoning_output_tokens",
|
||||
"total_tokens"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"hook_event_name": {
|
||||
"enum": [
|
||||
"PreModelRequest"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"hook_event_name"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"error": {
|
||||
"$ref": "#/definitions/NullableString"
|
||||
},
|
||||
"hook_event_name": {
|
||||
"enum": [
|
||||
"PostModelRequest"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/ModelRequestStatus"
|
||||
},
|
||||
"token_usage": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/TokenUsage"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"error",
|
||||
"hook_event_name",
|
||||
"status",
|
||||
"token_usage"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"agent_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"agent_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"cwd": {
|
||||
"$ref": "#/definitions/AbsolutePathBuf"
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
},
|
||||
"session_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"transcript_path": {
|
||||
"$ref": "#/definitions/NullableString"
|
||||
},
|
||||
"turn_id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"cwd",
|
||||
"model",
|
||||
"session_id",
|
||||
"transcript_path",
|
||||
"turn_id"
|
||||
],
|
||||
"title": "model-request.command.input",
|
||||
"type": "object"
|
||||
}
|
||||
Reference in New Issue
Block a user