You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -185,7 +185,7 @@ The `stream` method accepts three parameters directly:
185
185
}
186
186
187
187
# Process each chunk from your model's response
188
-
for chunk in response["stream"]:
188
+
asyncfor chunk in response["stream"]:
189
189
# Convert your model's event format to Strands Agents StreamEvent
190
190
if chunk.get("type") =="text_delta":
191
191
yield {
@@ -209,9 +209,9 @@ For more complex implementations, you may want to create helper methods to organ
209
209
210
210
```python
211
211
def_format_request(
212
-
self,
213
-
messages: Messages,
214
-
tool_specs: Optional[list[ToolSpec]] =None,
212
+
self,
213
+
messages: Messages,
214
+
tool_specs: Optional[list[ToolSpec]] =None,
215
215
system_prompt: Optional[str] =None
216
216
) -> dict[str, Any]:
217
217
"""Optional helper method to format requests for your model API."""
@@ -241,6 +241,8 @@ For more complex implementations, you may want to create helper methods to organ
241
241
returnNone
242
242
```
243
243
244
+
> Note, `stream` must be implemented async. If your client does not support async invocation, you may consider wrapping the relevant calls in a thread so as not to block the async event loop. For an example on how to achieve this, you can check out the [BedrockModel](https://github.com/strands-agents/sdk-python/blob/main/src/strands/models/bedrock.py) provider implementation.
245
+
244
246
### 3. Understanding StreamEvent Types
245
247
246
248
Your custom model provider needs to convert model's response events to Strands Agents [StreamEvent](../../../api-reference/types.md#strands.types.streaming.StreamEvent) format. The StreamEvent type supports these event types:
@@ -327,7 +329,7 @@ To support structured output in your custom model provider, you need to implemen
asyncfor event in process_stream(response, prompt):
343
345
yield event # Passed to callback handler configured in Agent instance
344
346
345
347
stop_reason, messages, _, _ = event["stop"]
@@ -366,6 +368,8 @@ def structured_output(
366
368
367
369
For detailed structured output usage patterns, see the [Structured Output documentation](../agents/structured-output.md).
368
370
371
+
> Note, similar to the `stream` method, `structured_output` must be implemented async. If your client does not support async invocation, you may consider wrapping the relevant calls in a thread so as not to block the async event loop. Again, for an example on how to achieve this, you can check out the [BedrockModel](https://github.com/strands-agents/sdk-python/blob/main/src/strands/models/bedrock.py) provider implementation.
372
+
369
373
### 5. Use Your Custom Model Provider
370
374
371
375
Once implemented, you can use your custom model provider in your applications for regular agent invocation:
0 commit comments