a2aproject / a2aproject/a2a-samples

`events` is a generator and cannot be indexed with `[-1]`

オープン
#38 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Jupyter Notebook
スター
1.8k
フォーク
751
PR マージ指標
30日以内にマージされた PR はありません

説明

This issue occurs in the **Agent example using ADK**, specifically within the `invoke` function.

Here is the problematic snippet:

```python
events = self._runner.run(
user_id=self._user_id, session_id=session.id, new_message=content
)
if not events or not events[-1].content or not events[-1].content.parts:
return ""
return "\n".join([p.text for p in events[-1].content.parts if p.text])
```

The variable `events` is a **generator**, but the code attempts to access it using `events[-1]`. This is not allowed, as generators do not support indexing or slicing.

Attempting this will raise a `TypeError`:

```
TypeError: 'generator' object is not subscriptable
```

### Workaround

Convert the generator to a list before performing any indexing:

```python
events = list(self._runner.run(
user_id=self._user_id, session_id=session.id, new_message=content
))
if not events or not events[-1].content or not events[-1].content.parts:
return ""
return "\n".join([p.text for p in events[-1].content.parts if p.text])
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。