Skip to content

Commit d5fddc6

Browse files
committed
Adding metadata
1 parent e061744 commit d5fddc6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,9 @@ class ModelRequest:
951951
run_id: str | None = None
952952
"""The unique identifier of the agent run in which this message originated."""
953953

954+
metadata: dict[str, Any] | None = None
955+
"""Additional data tagged on the message but is not sent to the model"""
956+
954957
@classmethod
955958
def user_text_prompt(cls, user_prompt: str, *, instructions: str | None = None) -> ModelRequest:
956959
"""Create a `ModelRequest` with a single user prompt as text."""
@@ -1195,6 +1198,9 @@ class ModelResponse:
11951198
run_id: str | None = None
11961199
"""The unique identifier of the agent run in which this message originated."""
11971200

1201+
metadata: dict[str, Any] | None = None
1202+
"""Additional data tagged on the message but is not sent to the model"""
1203+
11981204
@property
11991205
def text(self) -> str | None:
12001206
"""Get the text in the response."""

tests/test_messages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ def test_file_part_serialization_roundtrip():
463463
'provider_response_id': None,
464464
'finish_reason': None,
465465
'run_id': None,
466+
'metadata': None,
466467
}
467468
]
468469
)
@@ -475,11 +476,9 @@ def test_model_messages_type_adapter_preserves_run_id():
475476
ModelRequest(
476477
parts=[UserPromptPart(content='Hi there', timestamp=datetime.now(tz=timezone.utc))],
477478
run_id='run-123',
479+
metadata={'key': 'value'},
478480
),
479-
ModelResponse(
480-
parts=[TextPart(content='Hello!')],
481-
run_id='run-123',
482-
),
481+
ModelResponse(parts=[TextPart(content='Hello!')], run_id='run-123', metadata={'key': 'value'}),
483482
]
484483

485484
serialized = ModelMessagesTypeAdapter.dump_python(messages, mode='python')

0 commit comments

Comments
 (0)