Final referencing/answer agent assembling the final response.
| 335 | |
| 336 | @AgentRegistry.register('FinalRefer') |
| 337 | class FinalRefer(Node): |
| 338 | """Final referencing/answer agent assembling the final response.""" |
| 339 | def __init__( |
| 340 | self, |
| 341 | id: str | None = None, |
| 342 | domain: str = "", |
| 343 | llm_name: str = "", |
| 344 | llm_config: KVCommConfig | None = None, |
| 345 | ): |
| 346 | super().__init__(id, "FinalRefer" ,domain, llm_name) |
| 347 | prefix = "" |
| 348 | self.llm = LLMRegistry.get(llm_name, prefix=prefix, llm_config=llm_config) |
| 349 | self.role = 'FinalRefer' |
| 350 | self.llm.set_id(self.id, 'FinalRefer') |
| 351 | self.prompt_set = PromptSetRegistry.get(domain) |
| 352 | |
| 353 | async def _process_inputs( |
| 354 | self, |
| 355 | raw_inputs:Dict[str,str], |
| 356 | spatial_info:Dict[str,Any], |
| 357 | temporal_info:Dict[str,Any], |
| 358 | mode: str = "default", |
| 359 | **kwargs, |
| 360 | )->Dict[str, Any]: |
| 361 | """ To be overriden by the descendant class """ |
| 362 | """ Process the raw_inputs(most of the time is a List[Dict]) """ |
| 363 | if mode == "allow_kv_reuse": |
| 364 | request_uid = raw_inputs.get("_request_uid") or kwargs.get("request_uid") |
| 365 | if request_uid is None: |
| 366 | raise ValueError("request_uid is required for request-scoped anchor updates.") |
| 367 | |
| 368 | preferred_mode = "kv_reuse" |
| 369 | agent_memory = self.llm._ensure_agent_memory(self.id) |
| 370 | prefix_text = kwargs.get("prefix", "") |
| 371 | |
| 372 | has_shared_prefix = ( |
| 373 | self.llm.has_prefix_initialized(self.id) |
| 374 | and "placeholder_info" in agent_memory |
| 375 | ) |
| 376 | early_response: str | None = None |
| 377 | |
| 378 | if has_shared_prefix: |
| 379 | task = raw_inputs["task"] |
| 380 | for agent_id, info in spatial_info.items(): |
| 381 | cond_text: str | None = None |
| 382 | cond_prefix: str | None = None |
| 383 | |
| 384 | if self.domain == "gsm8k" and info["role"] == "Programming Expert": |
| 385 | answer = execute_code_get_return( |
| 386 | info["output"].split("```python\n")[-1].split("\n```")[0] |
| 387 | ) |
| 388 | if answer is None: |
| 389 | answer = "No variable is named answer." |
| 390 | cond_text = f"the answer is {answer}" |
| 391 | cond_prefix = "the answer is " |
| 392 | elif ( |
| 393 | self.domain == "humaneval" |
| 394 | and self.role not in {"Normal Programmer", "Stupid Programmer"} |
nothing calls this directly
no outgoing calls
no test coverage detected