Initialize the Agent. Args: name (str): The name of the role. env (Environment): The Jinja2 environment. record_cost (bool): Whether to record the token cost. llm (LLM): The language model. config (dict): The configuration
(
self,
name: str,
env: Environment,
record_cost: bool,
llm: LLM = None,
config: dict = None,
text_model: BGEM3FlagModel = None,
)
| 263 | """ |
| 264 | |
| 265 | def __init__( |
| 266 | self, |
| 267 | name: str, |
| 268 | env: Environment, |
| 269 | record_cost: bool, |
| 270 | llm: LLM = None, |
| 271 | config: dict = None, |
| 272 | text_model: BGEM3FlagModel = None, |
| 273 | ): |
| 274 | """ |
| 275 | Initialize the Agent. |
| 276 | |
| 277 | Args: |
| 278 | name (str): The name of the role. |
| 279 | env (Environment): The Jinja2 environment. |
| 280 | record_cost (bool): Whether to record the token cost. |
| 281 | llm (LLM): The language model. |
| 282 | config (dict): The configuration. |
| 283 | text_model (BGEM3FlagModel): The text model. |
| 284 | """ |
| 285 | self.name = name |
| 286 | if config is None: |
| 287 | with open(f"roles/{name}.yaml", "r") as f: |
| 288 | config = yaml.safe_load(f) |
| 289 | if llm is None: |
| 290 | llm = globals()[config["use_model"] + "_model"] |
| 291 | self.llm = llm |
| 292 | self.model = llm.model |
| 293 | self.record_cost = record_cost |
| 294 | self.text_model = text_model |
| 295 | self.return_json = config["return_json"] |
| 296 | self.system_message = config["system_prompt"] |
| 297 | self.prompt_args = set(config["jinja_args"]) |
| 298 | self.template = env.from_string(config["template"]) |
| 299 | self.retry_template = Template( |
| 300 | """The previous output is invalid, please carefully analyze the traceback and feedback information, correct errors happened before. |
| 301 | feedback: |
| 302 | {{feedback}} |
| 303 | traceback: |
| 304 | {{traceback}} |
| 305 | Give your corrected output in the same format without including the previous output: |
| 306 | """ |
| 307 | ) |
| 308 | self.system_tokens = len(ENCODING.encode(self.system_message)) |
| 309 | self.input_tokens = 0 |
| 310 | self.output_tokens = 0 |
| 311 | self.history: list[Turn] = [] |
| 312 | |
| 313 | def calc_cost(self, turns: list[Turn]): |
| 314 | """ |
nothing calls this directly
no test coverage detected