Files
NexQuant/rdagent/utils/agent/ret.py
T
you-n-g 5fca696be8 Agent Infra (#107)
* Agent Infra

* Update test/utils/test_agent_infra.py
2024-07-25 11:15:22 +08:00

34 lines
769 B
Python

"""
The output of a agent is very important.
We think this part can be shared.
"""
from abc import abstractclassmethod
import re
from typing import Any
from rdagent.utils.agent.tpl import T
class AgentOut:
@abstractclassmethod
def get_spec(cls, **context: Any) -> str:
raise NotImplementedError(f"Please implement the `get_spec` method")
@classmethod
def extract_output(cls, resp: str) -> Any:
raise resp
class PythonAgentOut(AgentOut):
@classmethod
def get_spec(cls):
return T(".tpl:PythonAgentOut").r()
@classmethod
def extract_output(cls, resp: str):
match = re.search(r".*```[Pp]ython\n(.*)\n```.*", resp, re.DOTALL)
if match:
code = match.group(1)
return code