Skip to content

Commit b3482a3

Browse files
committed
budget agent
1 parent 7387ed0 commit b3482a3

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

backend/agents/agents_framework.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
from .outreach_social_tool import OutreachSocialTool
1616
from .agent_permit import PermitSearchTool
1717
from .schedule_tool import ScheduleTool
18+
from .budget_tool import BudgetTool
1819

1920
resourse_search_tool = SearchTool()
2021
outreach_social_tool = OutreachSocialTool()
2122
schedule_tool = ScheduleTool()
23+
budget_tool = BudgetTool()
2224

23-
members = ["Resources", "Social_Outreach", "Volunteer_Outreach", "Schedule", "Permits"]
25+
members = ["Budget", "Resources", "Social_Outreach", "Volunteer_Outreach", "Schedule", "Permits"]
2426
options = members + ["FINISH"]
2527

2628
# Our team supervisor is an LLM node. It just picks the next agent to process
@@ -154,6 +156,30 @@
154156
"- Temporary Event Permit: Authorizes use of public space for the event.\n"
155157
)
156158

159+
budget_prompt = """You are an expert budget planning assistant specializing in all types of events. When a user asks about budget allocation:
160+
161+
1. Use the calculate_budget_breakdown tool to get the budget amount and event type
162+
2. Based on the event type, first determine ALL relevant budget categories that would be needed. Consider:
163+
- The specific nature and purpose of the event
164+
- Standard requirements for this type of event
165+
- Special equipment or resources typically needed
166+
- Both essential and optional components
167+
168+
3. For each identified category:
169+
- Assign an appropriate percentage based on importance and typical costs
170+
- Calculate the actual dollar amount
171+
172+
4. Your response should:
173+
- List all relevant budget categories specific to the event type
174+
- Show percentage and dollar amount for each category
175+
- Ensure percentages sum to exactly 100%
176+
- Group related items logically
177+
178+
Remember that categories should be specifically tailored to the exact event type provided, not using generic templates.
179+
Only output the answer, no other text.
180+
If you need any clarification about the event type or special requirements, ask the user.
181+
"""
182+
157183
prompt = ChatPromptTemplate.from_messages(
158184
[
159185
("system", system_prompt),
@@ -270,6 +296,23 @@ def permit_node(state: dict) -> Command[str]:
270296
goto="Supervisor",
271297
)
272298

299+
budget_agent = create_react_agent(
300+
llm,
301+
tools=[budget_tool],
302+
prompt=budget_prompt
303+
)
304+
305+
def budget_node(state: State) -> Command[Literal["Supervisor"]]:
306+
result = budget_agent.invoke(state)
307+
return Command(
308+
update={
309+
"messages": [
310+
HumanMessage(content=result["messages"][-1].content, name="Budget")
311+
]
312+
},
313+
goto="Supervisor",
314+
)
315+
273316
def supervisor_node(state: State) -> Command[Literal[*members, "__end__"]]:
274317
messages = [
275318
{"role": "system", "content": system_prompt},
@@ -291,6 +334,7 @@ def initialize_graph():
291334
builder.add_node("Volunteer_Outreach", outreach_volunteer_node)
292335
builder.add_node("Schedule", schedule_node)
293336
builder.add_node("Permits", permit_node)
337+
builder.add_node("Budget", budget_node)
294338
builder.set_entry_point("Supervisor")
295339
return builder.compile()
296340

backend/agents/budget_tool.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from pydantic import BaseModel, Field
2+
from langchain.tools import BaseTool
3+
from typing import Type
4+
from langchain_core.messages import HumanMessage
5+
from langchain_core.tools import tool
6+
7+
class BudgetInput(BaseModel):
8+
budget_str: str = Field(description="The budget amount and event type in the format 'amount:event_type'.")
9+
10+
class BudgetTool(BaseTool):
11+
name: str = "budget_tool"
12+
description: str = "Calculates budget allocation for a given event."
13+
args_schema: Type[BaseModel] = BudgetInput
14+
15+
def _run(self, budget_str: str) -> str:
16+
"""Calculate budget allocation based on the provided amount and event type."""
17+
try:
18+
amount, event_type = budget_str.split(':')
19+
amount = float(amount.replace('$', '').replace(',', ''))
20+
21+
# General budget breakdown prompt
22+
response = f"""
23+
You are an expert budget planning assistant specializing in all types of events. When a user asks about budget allocation:
24+
25+
1.⁠ ⁠Use the provided budget amount and event type to determine relevant budget categories.
26+
2.⁠ ⁠Assign an appropriate percentage based on importance and typical costs.
27+
3.⁠ ⁠Calculate the actual dollar amount for each category.
28+
29+
For example, if the user provides a budget of ${amount:,.2f} for a '{event_type}', you might allocate it as follows:
30+
31+
•⁠ ⁠Venue and setup: 10%, ${amount * 0.10:,.2f}
32+
•⁠ ⁠Equipment and supplies: 25%, ${amount * 0.25:,.2f}
33+
•⁠ ⁠Staff and coordination: 15%, ${amount * 0.15:,.2f}
34+
•⁠ ⁠Marketing and outreach: 15%, ${amount * 0.15:,.2f}
35+
•⁠ ⁠Administrative costs: 10%, ${amount * 0.10:,.2f}
36+
•⁠ ⁠Contingency fund: 25%, ${amount * 0.25:,.2f}
37+
38+
Remember that categories should be specifically tailored to the exact event type provided, not using generic templates.
39+
Only output the answer, no other text.
40+
If you need any clarification about the event type or special requirements, ask the user.
41+
"""
42+
return response.strip() # Return the response without leading/trailing whitespace
43+
44+
except ValueError:
45+
return "Invalid input format. Please use 'amount:event_type' format (e.g. '15000:community event')"
46+
47+
async def _arun(self, budget_str: str) -> str:
48+
"""Use this tool asynchronously."""
49+
raise NotImplementedError("Async not implemented")

0 commit comments

Comments
 (0)