Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Procurement Agent Demo
A demonstration of long-running, autonomous AI agents using Temporal and AgentEx. This agent manages construction procurement workflows that can run for months, respond to external events, and escalate to humans when needed.
What This Demo Shows
This demo illustrates a procurement manager for building construction that:
Key Concepts
Long-Running Workflows: Thanks to Temporal, the agent can live for months, surviving restarts and failures while maintaining full context.
External Event Integration: The agent receives real-world signals (not just user messages) via Temporal signals and takes autonomous actions.
Human-in-the-Loop: The agent can pause execution indefinitely (up to 24 hours) while waiting for human approval on critical decisions.
Learning System: When a human makes a decision, the agent extracts learnings and applies them to future similar situations.
State Management: Uses SQLite to persist construction schedules and procurement item status, providing queryable visibility into current operations without parsing conversation history.
Automatic Summarization: When conversation history exceeds token limits (~40k tokens), the agent automatically summarizes older messages while preserving recent context, enabling indefinite conversation length.
Example Workflow
Here's what happens when items move through the procurement pipeline:
Running the Demo
Prerequisites
You'll need three terminals running:
Step 1: Start AgentEx Backend
From the
scale-agentexrepository:This starts all required services (Postgres, Temporal, Redis, etc.) via Docker Compose. Verify everything is healthy:
# Optional: Use lazydocker for a better view lzdYou should see Temporal UI at: http://localhost:8080
Step 2: Start AgentEx Web UI
From the
scale-agentex-webrepository:The UI will be available at: http://localhost:3000
Step 3: Run the Procurement Agent
From this directory (
examples/demos/procurement_agent):The agent will start and register with the AgentEx backend on port 8000.
Step 4: Create a Task
Go to http://localhost:3000 and:
procurement-agentStep 5: Send Test Events
Now simulate real-world procurement events:
The script sends a series of events simulating the procurement lifecycle for multiple items:
Step 6: Observe the Agent
Watch the agent in action:
When an inspection fails, the agent will:
Project Structure
How It Works
1. Event-Driven Architecture
The agent receives events via Temporal signals in
workflow.py:Events are validated against Pydantic models and processed by the AI agent.
2. Human-in-the-Loop Pattern
Critical decisions require human approval via the
wait_for_humantool inprocurement_agent.py:The workflow continues only after receiving human input through the AgentEx UI.
3. State Management
Instead of cramming everything into the LLM context window, the agent uses SQLite to manage:
The database is accessed through Temporal activities with proper error handling and retry policies.
4. Learning System
When humans make decisions, the agent extracts learnings in
extract_learnings_agent.py:These learnings are passed into the agent's system prompt on subsequent runs.
5. Automatic Summarization
For long-running workflows, conversation history can grow unbounded. The agent automatically manages context using intelligent summarization:
Key features:
This enables workflows to run indefinitely without hitting context limits.
6. Error Handling & Retries
The workflow uses Temporal's retry policies for resilient execution:
Activities automatically retry on transient failures but fail fast on data corruption.
Key Features
Durability
External Event Processing
Human Escalation
Learning & Adaptation
Observability
Customizing the Demo
Modify the Construction Schedule
Edit the default schedule in
project/data/database.py:Add New Event Types
project/models/events.pyworkflow.pyprocurement_agent.pyproject/scripts/send_test_events.pyChange Agent Behavior
Modify the agent's instructions in
project/agents/procurement_agent.py:Add New Tools
Create new activities in
project/activities/activities.pyand register them as tools:Troubleshooting
Agent not appearing in UI
lsof -i :8000ENVIRONMENT=developmentis setEvents not being received
docker ps | grep temporalHuman escalation timeout
Database errors
project/data/procurement.dbrm project/data/procurement.dbImport errors
uv syncWhat's Next?
This demo shows the foundation for autonomous, long-running agents. Potential applications include:
The key insight: AI agents don't just answer questions—they can run real-world processes autonomously over time.
Learn More
Questions or issues? Open an issue on the scale-agentex GitHub repository.