Skip to content

Commit fc2c997

Browse files
authored
Add model_context property to AssistantAgent (#6072)
AssistantAgent initiation allows one to pass in a model_context, but there isn't a "public: way to get the existing model_context created by default.
1 parent e28738a commit fc2c997

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py

+7
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ def produced_message_types(self) -> Sequence[type[ChatMessage]]:
702702
message_types.append(ToolCallSummaryMessage)
703703
return tuple(message_types)
704704

705+
@property
706+
def model_context(self) -> ChatCompletionContext:
707+
"""
708+
The model context in use by the agent.
709+
"""
710+
return self._model_context
711+
705712
async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:
706713
async for message in self.on_messages_stream(messages, cancellation_token):
707714
if isinstance(message, Response):

python/packages/autogen-agentchat/tests/test_assistant_agent.py

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ async def test_model_context(monkeypatch: pytest.MonkeyPatch) -> None:
615615
]
616616
await agent.run(task=messages)
617617

618+
# Check that the model_context property returns the correct internal context
619+
assert agent.model_context == model_context
618620
# Check if the mock client is called with only the last two messages.
619621
assert len(model_client.create_calls) == 1
620622
# 2 message from the context + 1 system message

0 commit comments

Comments
 (0)