(
self,
send_message: Callable[
[str, Optional[str], int, Optional[Dict[str, Any]], Optional[str]],
Awaitable[None],
],
variant_index: int,
openai_api_key: Optional[str],
openai_base_url: Optional[str],
anthropic_api_key: Optional[str],
gemini_api_key: Optional[str],
replicate_api_key: Optional[str],
should_generate_images: bool,
asset_base_url: str = "",
initial_file_state: Optional[Dict[str, str]] = None,
option_codes: Optional[List[str]] = None,
)
| 21 | |
| 22 | class AgentEngine: |
| 23 | def __init__( |
| 24 | self, |
| 25 | send_message: Callable[ |
| 26 | [str, Optional[str], int, Optional[Dict[str, Any]], Optional[str]], |
| 27 | Awaitable[None], |
| 28 | ], |
| 29 | variant_index: int, |
| 30 | openai_api_key: Optional[str], |
| 31 | openai_base_url: Optional[str], |
| 32 | anthropic_api_key: Optional[str], |
| 33 | gemini_api_key: Optional[str], |
| 34 | replicate_api_key: Optional[str], |
| 35 | should_generate_images: bool, |
| 36 | asset_base_url: str = "", |
| 37 | initial_file_state: Optional[Dict[str, str]] = None, |
| 38 | option_codes: Optional[List[str]] = None, |
| 39 | ): |
| 40 | self.send_message = send_message |
| 41 | self.variant_index = variant_index |
| 42 | self.openai_api_key = openai_api_key |
| 43 | self.openai_base_url = openai_base_url |
| 44 | self.anthropic_api_key = anthropic_api_key |
| 45 | self.gemini_api_key = gemini_api_key |
| 46 | self.replicate_api_key = replicate_api_key |
| 47 | self.should_generate_images = should_generate_images |
| 48 | |
| 49 | self.file_state = AgentFileState() |
| 50 | if initial_file_state and initial_file_state.get("content"): |
| 51 | self.file_state.path = initial_file_state.get("path") or "index.html" |
| 52 | self.file_state.content = initial_file_state["content"] |
| 53 | |
| 54 | self.tool_runtime = AgentToolRuntime( |
| 55 | file_state=self.file_state, |
| 56 | should_generate_images=should_generate_images, |
| 57 | openai_api_key=openai_api_key, |
| 58 | openai_base_url=openai_base_url, |
| 59 | gemini_api_key=gemini_api_key, |
| 60 | replicate_api_key=replicate_api_key, |
| 61 | asset_base_url=asset_base_url, |
| 62 | option_codes=option_codes, |
| 63 | ) |
| 64 | self._tool_preview_lengths: Dict[str, int] = {} |
| 65 | |
| 66 | @staticmethod |
| 67 | def _extract_input_images( |
nothing calls this directly
no test coverage detected