-
Notifications
You must be signed in to change notification settings - Fork 288
feat: Add support for agent invoke with no input, or Message input #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
with this PR, what's the desired state when calling with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the PR description with the updated APIs and behaviors?
# Check if all item in input list are dictionaries | ||
elif all(isinstance(item, dict) for item in prompt): | ||
# Check if all items are messages | ||
if all(all(key in item for key in Message.__annotations__.keys()) for item in prompt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever using Message.__annotations__.keys
; and I like that
elif all(any(key in ContentBlock.__annotations__.keys() for key in item) for item in prompt): | ||
# Treat as List[ContentBlock] input - convert to user message | ||
# This allows invalid structures to be passed through to the model | ||
messages = [{"role": "user", "content": cast(list[ContentBlock], prompt)}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should have an else here doing something - raising a ValueError
@@ -597,6 +624,34 @@ async def _execute_event_loop_cycle(self, invocation_state: dict[str, Any]) -> A | |||
async for event in events: | |||
yield event | |||
|
|||
def _convert_prompt_to_messages(self, prompt: str | list[ContentBlock] | Messages | None) -> Messages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really glad we didn't add a Message
parameter to StartInvocationEvent
- it should now be messages
:)
@@ -597,6 +624,34 @@ async def _execute_event_loop_cycle(self, invocation_state: dict[str, Any]) -> A | |||
async for event in events: | |||
yield event | |||
|
|||
def _convert_prompt_to_messages(self, prompt: str | list[ContentBlock] | Messages | None) -> Messages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on turning str | list[ContentBlock] | Messages | None
into a type alias? Seems like we're copying it around and it might be helpful to have some Prompt (don't over index on the name) type
@@ -408,7 +408,7 @@ def end_event_loop_cycle_span( | |||
|
|||
def start_agent_span( | |||
self, | |||
message: Message, | |||
messages: Messages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlikely to be breaking anyone because of
def get_tracer() -> Tracer:
"""Get or create the global tracer.
Returns:
The global tracer instance.
"""
global _tracer_instance
if not _tracer_instance:
_tracer_instance = Tracer()
return _tracer_instance
?
Description
Allow an agent to be invoked with no input, or a list of messages
Related Issues
N/A
Documentation PR
N/A
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.