-
Notifications
You must be signed in to change notification settings - Fork 0
feat(model-routing): thread per-call model through InvokeModelStage #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -537,6 +537,7 @@ async def _handle_model_execution( | |
| tool_specs=copy.deepcopy(tool_specs), | ||
| tool_choice=copy.deepcopy(structured_output_context.tool_choice), | ||
| invocation_state=invocation_state, | ||
| model=agent.model, | ||
| projected_input_tokens=projected_input_tokens, | ||
| ) | ||
|
|
||
|
|
@@ -559,8 +560,7 @@ async def _handle_model_execution( | |
|
|
||
| if last_event is None: | ||
| raise RuntimeError( | ||
| "Middleware chain did not yield a result event. " | ||
| "Ensure middleware forwards events from next()." | ||
| "Middleware chain did not yield a result event. Ensure middleware forwards events from next()." | ||
| ) | ||
|
|
||
| # Write the post-stream model state back to the agent. Skipped on error | ||
|
|
@@ -663,7 +663,7 @@ def _make_invoke_model_terminal( | |
| async def terminal(ctx: InvokeModelContext) -> AsyncGenerator[Any, None]: | ||
| system_prompt_str, system_prompt_content = split_system_prompt(ctx.system_prompt) | ||
|
|
||
| model_id = agent.model.config.get("model_id") if hasattr(agent.model, "config") else None | ||
| model_id = ctx.model.config.get("model_id") if hasattr(ctx.model, "config") else None | ||
| model_invoke_span = tracer.start_model_invoke_span( | ||
| messages=ctx.messages, | ||
| parent_span=cycle_span, | ||
|
|
@@ -675,7 +675,7 @@ async def terminal(ctx: InvokeModelContext) -> AsyncGenerator[Any, None]: | |
| with trace_api.use_span(model_invoke_span, end_on_exit=False): | ||
| try: | ||
| async for event in stream_messages( | ||
| agent.model, | ||
| ctx.model, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue / question (re-posting here since my earlier comment targeted an unchanged line): Now that the terminal streams This is inert today since nothing overrides the model yet, so it's not blocking this PR. But please capture it as a known gap for the |
||
| system_prompt_str, | ||
| ctx.messages, | ||
| ctx.tool_specs, | ||
|
|
||
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.
Issue: The docstring here is updated nicely, but
src/strands/_middleware/README.md— the reference doc for middleware authors — is now stale. Its "Defensive copies" section enumerates the context fields (messages,system_prompt,tool_specs,tool_choice) and states that model state "is excluded from the context entirely … The terminal reads it directly from the agent at invocation time." Neither the newmodelfield nor its override capability is mentioned, so authors won't discover routing from the docs.Suggestion: Add
modelto the README's field discussion and note that middleware may replace it viadataclasses.replace()to redirect a single call. (Important)