Created
November 9, 2025 12:56
-
-
Save samirsaci/49a464d5db694594e8979c72e4d49608 to your computer and use it in GitHub Desktop.
AI Agents Budget Planning -AI Agent Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| from langchain.chat_models import init_chat_model | |
| from app.utils.config_loader import load_config | |
| from app.models.budagent_models import LaunchParamsBudget | |
| logger = logging.getLogger(__name__) | |
| config = load_config() | |
| class EmailParser: | |
| def __init__(self, model_name: str | None = None): | |
| model_name = config.get("budget_agent", {}).get( | |
| "model_name", "anthropic:claude-3-7-sonnet-latest" | |
| ) | |
| self.llm = init_chat_model(model_name) | |
| self.params: dict | None = None | |
| self.raw_email: str | None = None | |
| def parse(self, content: str | None = None) -> dict: | |
| """ | |
| Parse email content to extract parameters for API | |
| """ | |
| content = content.strip() | |
| system_prompt = config.get("budget_agent", {}).get( | |
| "system_prompt_parser", {} | |
| ) | |
| structured_llm = self.llm.with_structured_output(LaunchParamsBudget) | |
| result = structured_llm.invoke( | |
| [ | |
| {"role": "system", "content": system_prompt}, | |
| {"role": "user", "content": content}, | |
| ] | |
| ) | |
| payload = result.model_dump() | |
| self.params = payload | |
| logger.info(f"[BudgetAgent] Parsed params: {self.params}") | |
| return self.params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment