|
| 1 | +from typing_extensions import Protocol |
| 2 | +from agentlab.agents.agent_args import AgentArgs |
| 3 | + |
| 4 | + |
| 5 | +class MultiCandidateAgent(Protocol): |
| 6 | + """ |
| 7 | + Protocol for agents that generate multiple candidates for get_action. |
| 8 | +
|
| 9 | + This protocol defines the contract for agents that can generate |
| 10 | + multiple candidate actions and allow selection of one of them for execution. |
| 11 | + """ |
| 12 | + |
| 13 | + def get_candidate_generations( |
| 14 | + self, obs: dict, hint: list[str] | None = None, n_candidates: int = 3 |
| 15 | + ) -> list[dict]: |
| 16 | + """ |
| 17 | + Generate multiple candidate actions for the given observation. |
| 18 | + You can pass extra info in agent_info to update internal state of the |
| 19 | + agent based on the selected candidate. Your internal state management |
| 20 | + should be robust to multiple calls to the get_candidate_generations method |
| 21 | + in a single step. |
| 22 | +
|
| 23 | + Args: |
| 24 | + obs: The current observation dictionary containing environment state |
| 25 | + hint: Optional list of hint strings to guide candidate generation |
| 26 | + n_candidates: Number of candidate actions to generate |
| 27 | +
|
| 28 | + Returns: |
| 29 | + List of dictionaries, each containing: |
| 30 | + - 'action': The candidate action to be executed |
| 31 | + - 'agent_info': Additional information about the action generation |
| 32 | + """ |
| 33 | + ... |
| 34 | + |
| 35 | + def update_agent_state_from_selected_candidate(self, output: dict): |
| 36 | + """ |
| 37 | + Update the agent's internal state based on the selected candidate. |
| 38 | + This can include any memory or planning updates. |
| 39 | +
|
| 40 | + """ |
| 41 | + ... |
| 42 | + |
| 43 | + |
| 44 | +class MultiCandidateAgentArgs(AgentArgs): |
| 45 | + def make_agent(self) -> MultiCandidateAgent: ... |
| 46 | + |
| 47 | + def __post_init__(self): |
| 48 | + """Prefix subagent name with 'MC-'.""" |
| 49 | + super().__post_init__() |
| 50 | + if hasattr(self, 'agent_name') and self.agent_name: |
| 51 | + self.agent_name = "MC-" + self.agent_name |
0 commit comments