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