Skip to content

Conversation

yanxi0830
Copy link
Contributor

@yanxi0830 yanxi0830 commented Feb 21, 2025

@yanxi0830 yanxi0830 changed the base branch from main to agents_resume February 21, 2025 04:06
yanxi0830 added a commit to llamastack/llama-stack that referenced this pull request Feb 21, 2025
# What does this PR do?
- #1178
- #1187
- #1194

**client changes**
- llamastack/llama-stack-client-python#157
- llamastack/llama-stack-client-python#158

## Test Plan
```
LLAMA_STACK_BASE_URL=http://localhost:8321 pytest -v tests/client-sdk/agents/test_agents.py --inference-model meta-llama/Llama-3.1-8B-Instruct
```

```
LLAMA_STACK_CONFIG=fireworks pytest -v tests/client-sdk/agents/test_agents.py --inference-model meta-llama/Llama-3.1-8B-Instruct
```

<img width="1080" alt="image"
src="https://github.com/user-attachments/assets/6c48e062-5d00-4fed-98de-ecca627e5195"
/>

**llama-stack-apps**
```
python -m examples.agents.react_agent localhost 8321
```

- Test with script:
https://gist.github.com/yanxi0830/f2e407527f468998a700cd29fd271b15

**Output Before**: we have 2 `turn_id` with 2 turns
- https://gist.github.com/yanxi0830/9fbd7a80fcddc784a28c59d4a9c1d943

**Output After**: we have 1 `turn_id`, the final turn have all 3 steps
- https://gist.github.com/yanxi0830/17754d56d08ccbeaec419b693137500c

<img width="622" alt="image"
src="https://github.com/user-attachments/assets/ed7f42ca-41c8-4ee9-b6fa-2299901cafb4"
/>

**Telemetry**
<img width="1389" alt="image"
src="https://github.com/user-attachments/assets/031bf6ab-959c-46a7-aa85-70a511cba296"
/>


[//]: # (## Documentation)
Comment on lines +181 to +182
if n_iter == 0:
yield chunk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why yield when n_iter == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b/c when n_iter == 0, we will get back the actual Turn with turn_awaiting_input. e.g. https://gist.github.com/yanxi0830/17754d56d08ccbeaec419b693137500c

AgentTurnResponseStreamChunk(
│   event=TurnResponseEvent(
│   │   payload=AgentTurnResponseTurnAwaitingInputPayload(
│   │   │   event_type='turn_awaiting_input',
│   │   │   turn=Turn(
│   │   │   │   input_messages=[
│   │   │   │   │   UserMessage(
│   │   │   │   │   │   content='What is the boiling point of polyjuice in Celcius?',
│   │   │   │   │   │   role='user',
│   │   │   │   │   │   context=None
│   │   │   │   │   )
│   │   │   │   ],
│   │   │   │   output_message=CompletionMessage(
│   │   │   │   │   content='',
│   │   │   │   │   role='assistant',
│   │   │   │   │   stop_reason='end_of_turn',
│   │   │   │   │   tool_calls=[
│   │   │   │   │   │   ToolCall(
│   │   │   │   │   │   │   arguments={'liquid_name': 'polyjuice', 'celcius': 'True'},
│   │   │   │   │   │   │   call_id='782f2ba1-976d-45a5-874d-791c79ececf6',
│   │   │   │   │   │   │   tool_name='get_boiling_point'
│   │   │   │   │   │   )
│   │   │   │   │   ]
│   │   │   │   ),
│   │   │   │   session_id='8221e2f3-c4d3-44e7-ab7e-e74fdecb10e3',
│   │   │   │   started_at=datetime.datetime(2025, 2, 20, 21, 38, 8, 13477),
│   │   │   │   steps=[
│   │   │   │   │   InferenceStep(
│   │   │   │   │   │   api_model_response=CompletionMessage(
│   │   │   │   │   │   │   content='',
│   │   │   │   │   │   │   role='assistant',
│   │   │   │   │   │   │   stop_reason='end_of_turn',
│   │   │   │   │   │   │   tool_calls=[
│   │   │   │   │   │   │   │   ToolCall(
│   │   │   │   │   │   │   │   │   arguments={'liquid_name': 'polyjuice', 'celcius': 'True'},
│   │   │   │   │   │   │   │   │   call_id='782f2ba1-976d-45a5-874d-791c79ececf6',
│   │   │   │   │   │   │   │   │   tool_name='get_boiling_point'
│   │   │   │   │   │   │   │   )
│   │   │   │   │   │   │   ]
│   │   │   │   │   │   ),
│   │   │   │   │   │   step_id='c8a34ebd-2902-4da8-a78e-a549009880bb',
│   │   │   │   │   │   step_type='inference',
│   │   │   │   │   │   turn_id='38c0cc58-5c3b-4d8e-adf6-cb1c1a7bf0ee',
│   │   │   │   │   │   completed_at=datetime.datetime(2025, 2, 20, 21, 38, 8, 427067),
│   │   │   │   │   │   started_at=datetime.datetime(2025, 2, 20, 21, 38, 8, 24697)
│   │   │   │   │   )
│   │   │   │   ],
│   │   │   │   turn_id='38c0cc58-5c3b-4d8e-adf6-cb1c1a7bf0ee',
│   │   │   │   completed_at=datetime.datetime(2025, 2, 20, 21, 38, 8, 461543),
│   │   │   │   output_attachments=[]
│   │   │   )
│   │   )
│   )
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding: sorry am still confused. What about subsequent iteration? Why dont we need to yield? Might be good to add a comment here.

@yanxi0830 yanxi0830 merged commit cccd240 into agents_resume Feb 21, 2025
2 checks passed
@yanxi0830 yanxi0830 deleted the agents_resume_2 branch February 21, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants