Skip to content

Commit 7db111f

Browse files
committed
Add more logic
1 parent 2343a27 commit 7db111f

16 files changed

Lines changed: 626 additions & 154 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
venv/
25+
env/
26+
ENV/
27+
.venv
28+
29+
# IDE
30+
.vscode/
31+
.idea/
32+
*.swp
33+
*.swo
34+
*~
35+
36+
# Database files
37+
*.db
38+
*.sqlite
39+
*.sqlite3
40+
41+
# Environment variables
42+
.env
43+
.env.local
44+
45+
# Logs
46+
*.log
47+
48+
# OS
49+
.DS_Store
50+
Thumbs.db
51+
52+
# Jupyter
53+
.ipynb_checkpoints/
54+
*.ipynb_checkpoints
55+
56+
# Testing
57+
.pytest_cache/
58+
.coverage
59+
htmlcov/
60+
61+
# UV
62+
.venv/
63+
uv.lock

examples/demos/procurement_agent/project/activities.py

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Procurement agent activities module."""
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
from temporalio import activity, workflow
2+
import asyncio
3+
from datetime import timedelta, datetime
4+
import uuid
5+
import json
6+
7+
from agentex.lib.utils.logging import make_logger
8+
from project.models.events import (
9+
SubmitalApprovalEvent,
10+
ShipmentDepartedFactoryEvent,
11+
ShipmentArrivedSiteEvent,
12+
InspectionFailedEvent,
13+
)
14+
from project.data.database import (
15+
create_schedule_for_workflow,
16+
get_schedule_for_workflow,
17+
update_delivery_date_for_item_for_workflow,
18+
remove_delivery_item_for_workflow,
19+
update_project_end_date_for_workflow,
20+
)
21+
22+
logger = make_logger(__name__)
23+
24+
@activity.defn
25+
async def issue_purchase_order(event: SubmitalApprovalEvent) -> str:
26+
"""
27+
Issues a purchase order for construction materials.
28+
29+
Call this when:
30+
- A submittal is approved (Submittal_Approved event)
31+
- Human feedback requests reissuing a purchase order
32+
"""
33+
uuid_purchase_order = str(uuid.uuid4())
34+
# wait for 5 seconds as if we were calling an API to issue a purchase order
35+
await asyncio.sleep(5)
36+
logger.info(f"Issuing purchase order: {event}")
37+
logger.info(f"Purchase order ID: {uuid_purchase_order}")
38+
39+
return f"Successfully issued purchase order with ID: {uuid_purchase_order}"
40+
41+
@activity.defn
42+
async def flag_potential_issue(event: ShipmentDepartedFactoryEvent) -> str:
43+
"""
44+
Flags a potential issue with a delivery date.
45+
46+
Call this when:
47+
- A shipment departure creates timeline concerns (Shipment_Departed_Factory event)
48+
- Human feedback identifies a potential delivery issue
49+
"""
50+
logger.info(f"Flagging potential issue: {event}")
51+
logger.info(f"Potential issue flagged with delivery date: {event.eta}")
52+
# imagine this is a call to an API to flag a potential issue, perhaps a notification to a team member
53+
await asyncio.sleep(1)
54+
return f"Potential issue flagged with delivery date: {event.eta}"
55+
56+
@activity.defn
57+
async def notify_team_shipment_arrived(event: ShipmentDepartedFactoryEvent) -> str:
58+
"""
59+
Notifies the team that a shipment has arrived.
60+
61+
Call this when:
62+
- A shipment arrives at the site (Shipment_Arrived_Site event)
63+
- Human feedback requests team notification
64+
"""
65+
logger.info(f"Notifying team that shipment has arrived: {event.item}")
66+
logger.info(f"Team notification sent for arrival of: {event.item}")
67+
# imagine this is a call to an API to notify the team that a shipment has arrived, perhaps a notification to a team member
68+
await asyncio.sleep(1)
69+
70+
return f"Notifying team that shipment has arrived: {event.item}"
71+
72+
@activity.defn
73+
async def schedule_inspection(event: ShipmentDepartedFactoryEvent) -> str:
74+
"""
75+
Schedules an inspection for delivered materials.
76+
77+
Call this when:
78+
- A shipment arrives at the site (Shipment_Arrived_Site event)
79+
- Human feedback requests scheduling an inspection
80+
"""
81+
inspection_date = datetime.now() + timedelta(days=1)
82+
logger.info(f"Scheduling inspection for: {event.item} on {inspection_date}")
83+
# imagine this is a call to an API to schedule an inspection
84+
await asyncio.sleep(1)
85+
return f"Scheduling inspection for {event.item} on {inspection_date}"
86+
87+
88+
89+
@activity.defn
90+
async def create_master_construction_schedule(workflow_id: str) -> str:
91+
"""
92+
Creates the master construction schedule for the workflow.
93+
94+
Call this when:
95+
- The workflow is created
96+
97+
Args:
98+
workflow_id: The Temporal workflow ID
99+
"""
100+
logger.info(f"Creating master construction schedule for workflow: {workflow_id}")
101+
await create_schedule_for_workflow(workflow_id)
102+
return "Master construction schedule created for workflow"
103+
104+
@activity.defn
105+
async def get_master_construction_schedule(workflow_id: str) -> str:
106+
"""
107+
Gets the master construction schedule for the workflow.
108+
109+
Call this when:
110+
- You want to get the master construction schedule for the workflow
111+
- Human feedback requests the master construction schedule
112+
113+
Returns:
114+
The master construction schedule for the workflow
115+
"""
116+
schedule = await get_schedule_for_workflow(workflow_id)
117+
if schedule is None:
118+
return "No master construction schedule found for workflow"
119+
120+
logger.info(f"Master construction schedule found for workflow: {workflow_id}")
121+
logger.info(f"Master construction schedule: {schedule}")
122+
return json.dumps(schedule)
123+
124+
@activity.defn
125+
async def update_delivery_date_for_item(workflow_id: str, item: str, new_delivery_date: str) -> str:
126+
"""
127+
Updates the delivery date for a specific item in the construction schedule.
128+
129+
Call this when:
130+
- You want to update the delivery date for a specific item in the construction schedule
131+
- Human feedback requests updating the delivery date for a specific item
132+
133+
Args:
134+
workflow_id: The Temporal workflow ID
135+
item: The item to update
136+
new_delivery_date: The new delivery date
137+
"""
138+
logger.info(f"Updating delivery date for item: {item} to {new_delivery_date}")
139+
await update_delivery_date_for_item_for_workflow(workflow_id, item, new_delivery_date)
140+
return f"Delivery date updated for item: {item} to {new_delivery_date}"
141+
142+
@activity.defn
143+
async def remove_delivery_item(workflow_id: str, item: str) -> str:
144+
"""
145+
Removes a delivery item from the construction schedule.
146+
147+
Call this when:
148+
- You want to remove a delivery item from the construction schedule
149+
- Human feedback requests removing a delivery item
150+
151+
Args:
152+
workflow_id: The Temporal workflow ID
153+
item: The item to remove
154+
"""
155+
logger.info(f"Removing delivery item: {item}")
156+
await remove_delivery_item_for_workflow(workflow_id, item)
157+
return f"Delivery item removed from construction schedule: {item}"
158+
159+
@activity.defn
160+
async def update_project_end_date(workflow_id: str, new_end_date: str) -> str:
161+
"""
162+
Updates the end date for the project in the construction schedule.
163+
164+
Call this when:
165+
- You want to update the end date for the project in the construction schedule
166+
- Human feedback requests updating the end date for the project
167+
168+
Args:
169+
workflow_id: The Temporal workflow ID
170+
new_end_date: The new end date for the project
171+
"""
172+
logger.info(f"Updating end date for project to: {new_end_date}")
173+
await update_project_end_date_for_workflow(workflow_id, new_end_date)
174+
return f"End date updated for project: {new_end_date}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Procurement agent agents module."""

0 commit comments

Comments
 (0)