Supply Chain Optimization using "Agents as Tools" Pattern
VSCode Users: This project includes optimized VSCode settings and extension recommendations in .vscode/
. Simply open the project in VSCode and install the recommended extensions when prompted.
First copy the .env.example
file to a new file called .env
in the same directory and enter your OPENAI_API_KEY
-
Install & Setup:
./install.sh cp .env.example .env # Add your OpenAI API key to .env
-
Activate Environment (once per session IMPORTANT!):
source .venv/Scripts/activate # Windows source .venv/bin/activate # Mac/Linux
Why? Virtual environment isolates project dependencies from your system Python.
Check you're in venv: Command prompt shows
(oxford-ai-2025-group1-full-code)
prefixTo exit venv:
deactivate
(when done working)β οΈ Always ensure you're in the venv before running any Python commands or tests! -
Test Installation:
python -m pytest -m agent01 # Test your agent python run.py # Run full system
All agent and tool interactions are automatically logged!
π Full Logging Guide: Getting_Started/02_Logging_Guide.md
- Complete logging configuration instructions
- Test execution with full visibility
- Log analysis and debugging commands
- Development workflow with logging
π Read the Course Guide: Getting_Started/01_Course_Guide.md
- Assignment requirements & evaluation criteria
- Step-by-step implementation approach
- Submission guidelines & deadlines
π Copy the Sample Notebook (don't use the original!):
- Template to copy:
notebooks/samples/agent01_sample_demo.ipynb
- Guide:
notebooks/samples/README_agent01_sample.md
Two-level development approach:
- Quick testing β Use your
tests/
folder for rapid development and small changes - Document iterations β Use your copied notebook to capture significant improvements
Daily workflow: Edit code β Run tests with logging β Review logs β When happy β Document in notebook
Agent | Team Member | Purpose | Location | Quick Guide |
---|---|---|---|---|
01 | Martin | Inventory Threshold Monitor | src/logistics_agents/agents/agent_01_threshold_monitor/ |
README.md |
02 | Rhiannon | Route Computer | src/logistics_agents/agents/agent_02_route_computer/ |
README.md |
03 | Nathan | Restocking Calculator | src/logistics_agents/agents/agent_03_restock_calculator/ |
README.md |
04 | Anagha | Order Consolidator | src/logistics_agents/agents/agent_04_order_consolidator/ |
README.md |
05 | Andy | Orchestrator | src/logistics_agents/agents/agent_05_orchestrator/ |
README.md |
oxford-ai-2025-group1-full-code/
βββ Getting_Started/
β βββ 01_Course_Guide.md # Course requirements & guidelines
βββ notebooks/
β βββ samples/
β βββ agent01_sample_demo.ipynb # Notebook template (copy this!)
β βββ README_agent01_sample.md # Iteration workflow guide
βββ logs/ # π AUTO-GENERATED LOG FILES
β βββ logistics_agents_YYYYMMDD_HHMMSS_username.log
βββ data/
β βββ final_customer_location_aligned.csv # Real inventory data (100+ items)
β βββ outputs/ # Analysis results
βββ src/
β βββ logistics_agents/
β βββ main.py # Application entry point
β βββ config/ # Configuration management
β βββ models/ # Data models & schemas
β βββ utils/ # Shared utilities & data loading
β β βββ logging_config.py # π ENHANCED LOGGING SYSTEM
β β βββ agent_runner.py # π LOGGED AGENT EXECUTION
β βββ agents/ # Individual agent implementations
β βββ conftest.py # Shared test fixtures
β βββ agent_01_threshold_monitor/ # Martin's agent
β β βββ agent.py # Main agent implementation
β β βββ tools/ # Function tools (@function_tool)
β β β βββ threshold_checker.py # π WITH LOGGING
β β β βββ priority_classifier.py # π WITH LOGGING
β β βββ tests/ # Unit tests
β β βββ README.md # Agent-specific docs
β βββ agent_02_route_computer/ # Rhiannon's agent
β βββ agent_03_restock_calculator/ # Nathan's agent
β βββ agent_04_order_consolidator/ # Anagha's agent
β βββ agent_05_orchestrator/ # Andy's agent
βββ install.sh # Setup script
βββ run.py # Run application
βββ pyproject.toml # Dependencies
Quick Testing with Logging (use for rapid development):
# Basic testing with logging output
python -m pytest -m agent01 -v -s --log-cli-level=INFO
python -m pytest -m agent02 -v -s --log-cli-level=INFO
python -m pytest -m agent03 -v -s --log-cli-level=INFO
python -m pytest -m agent04 -v -s --log-cli-level=INFO
python -m pytest -m agent05 -v -s --log-cli-level=INFO
# Detailed testing with full input/output logging
python -m pytest -m agent01 -v -s --log-cli-level=DEBUG --tb=short
# All tests with logging
python -m pytest -v -s --log-cli-level=INFO
python -m pytest -m integration -v -s --log-cli-level=INFO
Cost-Aware Testing (manage OpenAI API usage):
# Run cheap tests only (skip expensive orchestration)
python -m pytest -m "agent05 and not expensive" -v -s --log-cli-level=INFO
# Run the full end-to-end orchestration test (expensive!)
python -m pytest -m "agent05 and expensive" -v -s --log-cli-level=INFO
# Run all agents except expensive tests
python -m pytest -m "not expensive" -v -s --log-cli-level=INFO
π For detailed logging commands: See Getting_Started/02_Logging_Guide.md
Course Documentation (use for iteration capture):
python -m jupyterlab # Start notebooks for iteration documentation
python run.py # Test full system integration (creates log file)
- Read the Course Guide to understand requirements
- Copy the sample notebook and rename for your agent (e.g.,
agent02_rhiannon_demo.ipynb
) - Work in your agent folder (
src/logistics_agents/agents/agent_XX_*/
) - Use tests for quick development (
python -m pytest -m agentXX -v -s --log-cli-level=INFO
) - Review logs to understand agent/tool interactions (
logs/
folder) - Use notebook for documented iterations (significant improvements only)
Remember:
- Tests + Logs = quick development with full visibility
- Notebook = course iteration documentation
- Check
/logs/
folder after every run for detailed execution traces
Each specialist agent implements domain expertise and can be used as a tool by the orchestrator agent, enabling dynamic coordination based on real-time logistics conditions.
All interactions are automatically logged for learning and debugging!
Ready to start? β Getting_Started/01_Course_Guide.md
%% =============================================================================
%% LOGISTICS AGENTS SYSTEM ARCHITECTURE - "Agents as Tools" Pattern
%% =============================================================================
%% Overall System Architecture
graph TB
subgraph "π’ Logistics Multi-Agent System"
Main["π main.py<br/>Entry Point"] --> Orchestrator["π― Agent 05<br/>Orchestrator<br/>(Andy)"]
subgraph "ποΈ Orchestrator Tools"
OT1["π agent_coordinator"]
OT2["π result_synthesizer"]
end
subgraph "π§ Specialist Agents (as Tools)"
Agent01["π¨ Agent 01<br/>Threshold Monitor<br/>(Martin)"]
Agent02["πΊοΈ Agent 02<br/>Route Computer<br/>(Rhiannon)"]
Agent03["π Agent 03<br/>Restock Calculator<br/>(Nathan)"]
Agent04["π¦ Agent 04<br/>Order Consolidator<br/>(Anagha)"]
end
Orchestrator --> OT1
Orchestrator --> OT2
Orchestrator -.->|"as_tool()"| Agent01
Orchestrator -.->|"as_tool()"| Agent02
Orchestrator -.->|"as_tool()"| Agent03
Orchestrator -.->|"as_tool()"| Agent04
end
subgraph "π Data Flow"
CSV["π Inventory CSV"] --> Context["ποΈ InventoryContext"]
Context --> Orchestrator
end
style Orchestrator fill:#e1f5fe,stroke:#0277bd,stroke-width:3px
style Agent01 fill:#fff3e0,stroke:#f57c00,stroke-width:2px
style Agent02 fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
style Agent03 fill:#e8f5e8,stroke:#388e3c,stroke-width:2px
style Agent04 fill:#fce4ec,stroke:#c2185b,stroke-width:2px
graph TD
subgraph "π― Agent 05 - Orchestrator Workflow (Andy)"
Start["π Start Analysis"] --> Coord["π coordinate_workflow_steps<br/>Plan execution sequence"]
Coord --> Step1["1οΈβ£ Call InventoryThresholdMonitor<br/>Identify urgent items"]
Step1 --> Step2["2οΈβ£ Call RestockingCalculator<br/>Calculate optimal quantities"]
Step2 --> Step3["3οΈβ£ Call RouteComputer<br/>Plan delivery routes"]
Step3 --> Step4["4οΈβ£ Call OrderConsolidator<br/>Optimize order grouping"]
Step4 --> Synth["π create_executive_summary<br/>Synthesize all results"]
Synth --> Final["π Final Recommendations<br/>Comprehensive logistics plan"]
end
subgraph "π Agents as Tools Pattern"
AgentTools["π§ Specialist Agents Available as Tools"]
AgentTools --> T1["π¨ InventoryThresholdMonitor.as_tool()"]
AgentTools --> T2["πΊοΈ RouteComputer.as_tool()"]
AgentTools --> T3["π RestockingCalculator.as_tool()"]
AgentTools --> T4["π¦ OrderConsolidator.as_tool()"]
end
Step1 -.-> T1
Step2 -.-> T3
Step3 -.-> T2
Step4 -.-> T4
style Start fill:#e1f5fe,stroke:#0277bd,stroke-width:3px
style Final fill:#e8f5e8,stroke:#388e3c,stroke-width:3px
style Coord fill:#fff3e0,stroke:#f57c00,stroke-width:2px
style Synth fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
sequenceDiagram
participant CSV as π CSV Data
participant Main as π main.py
participant Orch as π― Orchestrator
participant A01 as π¨ Agent 01<br/>Threshold
participant A03 as π Agent 03<br/>Restock Calc
participant A02 as πΊοΈ Agent 02<br/>Route Comp
participant A04 as π¦ Agent 04<br/>Consolidator
CSV->>Main: Load inventory data
Main->>Orch: InventoryContext
Note over Orch: π coordinate_workflow_steps
Orch->>A01: Analyze thresholds
A01->>A01: threshold_checker
A01->>A01: priority_classifier
A01->>Orch: Priority items + urgency
Orch->>A03: Calculate quantities
A03->>A03: demand_forecaster
A03->>A03: quantity_optimizer
A03->>Orch: Optimal quantities + costs
Orch->>A02: Plan routes
A02->>A02: route_calculator
A02->>A02: delivery_scheduler
A02->>Orch: Routes + schedules
Orch->>A04: Consolidate orders
A04->>A04: supplier_matcher
A04->>A04: order_optimizer
A04->>Orch: Consolidated orders + savings
Note over Orch: π create_executive_summary
Orch->>Main: Final recommendations
Main->>Main: π Display results