Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,14 @@ async def main():

# Stream the content
async for chunk in response.output:
async for chunk in response.output:
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
else:
print(f"Received unexpected chunk type: {type(chunk)}", file=sys.stderr)
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
else:
print(f"Received unexpected chunk type: {type(chunk)}", file=sys.stderr)
print()

else:
# Handle non-streaming response (AgentProcessingResult)
# Handle non-streaming response (ConversationMessage)
print("\n** RESPONSE ** \n")
print(f"> Agent ID: {response.metadata.agent_id}")
print(f"> Agent Name: {response.metadata.agent_name}")
Expand Down
16 changes: 13 additions & 3 deletions docs/src/content/docs/cookbook/examples/python-local-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ from agent_squad.orchestrator import AgentSquad, AgentSquadConfig
from agent_squad.agents import (BedrockLLMAgent,
BedrockLLMAgentOptions,
AgentResponse,
AgentCallbacks)
AgentCallbacks,
AgentStreamResponse)
from agent_squad.types import ConversationMessage, ParticipantRole

orchestrator = AgentSquad(options=AgentSquadConfig(
Expand Down Expand Up @@ -71,11 +72,20 @@ orchestrator.add_agent(tech_agent)
4. Implement the main logic:
```python
async def handle_request(_orchestrator: AgentSquad, _user_input: str, _user_id: str, _session_id: str):
response: AgentResponse = await _orchestrator.route_request(_user_input, _user_id, _session_id)
response: AgentResponse = await _orchestrator.route_request(
_user_input,
_user_id,
_session_id,
stream_response=True,
)
print("\nMetadata:")
print(f"Selected Agent: {response.metadata.agent_name}")
if response.streaming:
print('Response:', response.output.content[0]['text'])
print('Response:', end=' ')
async for chunk in response.output:
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
print()
else:
print('Response:', response.output.content[0]['text'])

Expand Down
16 changes: 13 additions & 3 deletions docs/src/content/docs/general/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Ensure you have [requested access](https://docs.aws.amazon.com/bedrock/latest/us
from agent_squad.agents import (BedrockLLMAgent,
BedrockLLMAgentOptions,
AgentResponse,
AgentCallbacks)
AgentCallbacks,
AgentStreamResponse)
from agent_squad.types import ConversationMessage, ParticipantRole

orchestrator = AgentSquad(options=AgentSquadConfig(
Expand Down Expand Up @@ -248,12 +249,21 @@ Ensure you have [requested access](https://docs.aws.amazon.com/bedrock/latest/us
<TabItem label="Python" icon="seti:python">
```python
async def handle_request(_orchestrator: AgentSquad, _user_input: str, _user_id: str, _session_id: str):
response: AgentResponse = await _orchestrator.route_request(_user_input, _user_id, _session_id)
response: AgentResponse = await _orchestrator.route_request(
_user_input,
_user_id,
_session_id,
stream_response=True,
)
# Print metadata
print("\nMetadata:")
print(f"Selected Agent: {response.metadata.agent_name}")
if response.streaming:
print('Response:', response.output.content[0]['text'])
print('Response:', end=' ')
async for chunk in response.output:
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
print()
else:
print('Response:', response.output.content[0]['text'])

Expand Down
12 changes: 6 additions & 6 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ async def main():

# Stream the content
async for chunk in response.output:
async for chunk in response.output:
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
else:
print(f"Received unexpected chunk type: {type(chunk)}", file=sys.stderr)
if isinstance(chunk, AgentStreamResponse):
print(chunk.text, end='', flush=True)
else:
print(f"Received unexpected chunk type: {type(chunk)}", file=sys.stderr)
print()

else:
# Handle non-streaming response (AgentProcessingResult)
# Handle non-streaming response (ConversationMessage)
print("\n** RESPONSE ** \n")
print(f"> Agent ID: {response.metadata.agent_id}")
print(f"> Agent Name: {response.metadata.agent_name}")
Expand Down