
状態の定義
次に、
AgentState
型を定義して、エージェントの状態を管理します。
# 状態管理
class AgentState(TypedDict):
messages: Annotated[Sequence[BaseMessage], operator.add]
next: str
task: str
messages
フィールドは、エージェント間のメッセージのやりとりを保存するために使用し
ます。
Annotated
を使って
operator.add
を指定することで、更新時にメッセージを追加するこ
とを指定します。
next
フィールドは、次にアクションを行うエージェントを指定するために
使用します。
task
フィールドは、開発タスクの内容を保存するために使用します。
エージェントの定義
次の部分では、各エージェントのプロンプトテンプレートと、エージェントを生成する関数
を定義しています。まず、リーダの出力を定義する
LeaderResponse
クラスを定義します。
class LeaderResponse(BaseModel):
reasoning: str = Field(description="決定の背後にある理由。")
next: Union[Literal["Finish"], str] = Field(
description="次にアクションを行うチームメンバ。"
)
instructions: str = Field(description="次のチームメンバへの指示。")
reasoning ...