Email agent for a hotels that support informational and transactional requests. Supports auto and human in the loop mode.
Start with a deterministic setup (in our case that is 3 staged planners, policy validator and DAG executor). Only once the limitations of this approach are identified, start to think about more agentic loop based or multi-agent approach.
- Agent implementation is done through langgraph, using an
InMemorySaverfor checkpointing. - Tools are implemented as langchain tools with additional tool registry.
- Application is served through FastAPI. Exposing 2 workflow endpoints:
/emailfor handling new email requests./email/{run_id}/resumefor resuming a workflow from approval or rejection.
- Evals are done using PromptFoo.
Install the dependencies using uv.
uv syncCopy the .env.example file to .env and fill in the values.
TIMEZONE: Timezone for date/time context in prompts (default:UTC). Uses IANA timezone formatDEFAULT_AGENT_MODE: Agent operation modehitlorauto(default:hitl)OPENAI_API_KEY: OpenAI API key for LLM calls
If you want to view full traces in langsmith, you can set the LANGSMITH_TRACING to true and set the LANGSMITH_ENDPOINT, LANGSMITH_PROJECT and LANGSMITH_API_KEY to your langsmith credentials. You can get the credentials from your langsmith dashboard.
LANGSMITH_TRACING=true
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_PROJECT=
LANGSMITH_API_KEY=In src/main.py, you can configure the hotel configuration by modifying the get_hotel_config function.
This is supposed to come from the database in a real world application.
You can change the agent_mode and action_policies (expanded below) to test different behaviour.
To run the invoke the agent through FastAPI endpoints, you can use the following command:
uv run uvicorn src.main:app --reloadThis will start the FastAPI server on http://localhost:8000.
You can find a Postman collection in the extra directory.
Import the collection into Postman and use the endpoints to test the application.
It contains examples for the email and email/{run_id}/resume endpoints.
The project include evals for the goal planner, context planner and action planner.
To run evals, you need to have PromptFoo installed. You can install it with npm install -g promptfoo.
Or with the latest npm version, you can run it via npx promptfoo rather than promptfoo.
Run evals from the evals directory.
cd evalspromptfoo eval --config promptfooconfig.goal_planner.yaml
promptfoo eval --config promptfooconfig.context_planner.yaml
promptfoo eval --config promptfooconfig.action_planner.yamlIf you want to view the evals, you can run:
promptfoo viewIf you want to clear cache after making changes, you can run:
promptfoo cache clearEval results can be found in the evals/results/ directory.
promptfoo eval --config promptfooconfig.goal_planner.yaml
eval-owY-2026-04-09T19_55_26.json
Results:
✓ 32 passed (100%)
0 failed (0%)
0 errors (0%)
Duration: 1m 15s (concurrency: 4)promptfoo eval --config promptfooconfig.context_planner.yaml
eval-i1v-2026-04-09T19_29_43.json
Results:
✓ 10 passed (100%)
0 failed (0%)
0 errors (0%)
Duration: 26s (concurrency: 4)promptfoo eval --config promptfooconfig.action_planner.yaml
eval-jlK-2026-04-09T19_38_57.json
Results:
✓ 21 passed (91.30%)
✗ 2 failed (8.70%)
0 errors (0%)
Duration: 1m 9s (concurrency: 4)- Cancel + Rebooking, multiple actions needs improvement in instructions / policies.
- Modify reservation needs 'ambiguous' flagging similar to create booking in policies.
A thread started from guest inquiring for rates and availability.
Response.
Further inquiry for different rooms.
Response.
Requesting reservation.The scope does not mention it, and none of the scenarios imply that this is expected.
Assumption: It is out of scope of this task, only single email requests are supported.
In Human approval mode, can the hotel staff approve one action, and reject another?
Given one email typically only maps to one write action against the reservation model;
Assumption: The approval is at the plan level and NOT at a tool level.
Static hotel and policy information is limited and separated already with the mock PMS data.
Also the focus of the task is around the "actions".
Assumption: A semantic search / retrieval layer is not expected.
Using the same email endpoint for both new requests and resuming from approval or rejection adds additional complexity to the workflow.
Assumption: The approval flow is separate from the core email workflow.
- Changed year in the mock PMS data to 2026 (and added a
nowcontext in the prompts).
Following the core principle, the agent design is deterministic, more on the workflow side rather than agentic side.
This is a visualisation of the agent graph. It is generated using the /visualise-agent?output_format={png,mermaid} endpoint.
graph TD;
__start__([<p>__start__</p>]):::first
goal_planner(goal_planner)
context_planner(context_planner)
context_executor(context_executor)
draft_generator(draft_generator)
action_planner(action_planner)
gated_executor(gated_executor)
action_executor(action_executor)
rejection_response_generator(rejection_response_generator)
error_fallback_generator(error_fallback_generator)
final_response_generator(final_response_generator)
__end__([<p>__end__</p>]):::last
__start__ --> goal_planner;
action_executor -.-> error_fallback_generator;
action_executor -.-> final_response_generator;
action_planner --> draft_generator;
context_executor -.-> action_planner;
context_executor -.-> draft_generator;
context_executor -.-> final_response_generator;
context_planner --> context_executor;
draft_generator -.-> action_executor;
draft_generator -.-> gated_executor;
gated_executor -.-> action_executor;
gated_executor -.-> final_response_generator;
gated_executor -.-> rejection_response_generator;
goal_planner --> context_planner;
error_fallback_generator --> __end__;
final_response_generator --> __end__;
rejection_response_generator --> __end__;
classDef default fill:#f2f0ff,line-height:1.2
classDef first fill-opacity:0
classDef last fill:#bfb6fc
Unless proven to be insufficient with clear scenarios, a deterministic approach is preferred because of the following reasons:
- It is easier to reason about the workflow and the decisions made by the agent.
- Predictable flow and clear failure indications.
- Predictable cost and latency.
- Debugging and Reproducibility.
A Multi-agent / Supervisor Orchastrator approach can be used to address more open-ended tasks.
The agent design consists of 3 planners:
Goal Planner: Identifies the action goals based on the email content.
- No tools awareness: this is to not bias the model towards the tools available. And use model's core reasoning abilities to comeup with a highlevel plan. Understanding of the guest's intent, inferring requirements and constraints without molding it agent's capabilities.
- This gives us 2 different types of goals: context goals and action goals.
Context Planner: Gathers the context information needed to fulfill the action goals.
- Based on the context goals, and being aware of the tools available, context planner builds a plan to gather the context information needed to fulfill the action goals downstream.
- Only context tools are used in this stage.
- Tool categorisation reduces the context size, lesser tools to consider for the planner. And it also avoid mistakenly planning to use to action tools in this stage. (deterministic control)
Action Planner: Builds the action plan / flag based on the action goals and the context results.
- Once the context execution is complete, the required information is now available to make decision about the actions.
- Flag the actions that are risky or ambiguous and need human review.
- Having the full context available allows to prepare action plan and reason about action flags at the same time.
- Downstream nodes decide to execute the actions or not based on the flags & agent mode (auto or hitl).
- A list of rules/ guidelines that would be derived from the policies and then finetuned by the agent (human / auto) to improve agent's decision making.
- For now they are just ad-hoc rules, but they can be extended to be more formal and part of the policy validation process.
- Tool registry is basically a dictionary of tools that are available to the agent.
- Tool Categorisation is used to group tools into context and action tools. This gives us control over the tools that are available to the planner.
- Additional response instructions to the tools improve the response quality / fallback.
- Dynamic context such as current date & time, guest information, filter options are injected into the prompts.
- To make the planner (context & action) more accurate, appropriate decoration (docstring, registry) is used.
- Improvement scope: more walk-throughs (examples with reasoning) and few-shot examples.
- Matured library, gives us everything we need to build the designed agent.
- My experience with it has been positive, and I am comfortable with it.
- Improve Action Planner's planning & flagging accuracy.
- Strengthen evals : add more matrices, scenarios in data-set, cover all LLM calls.
- Support for multi-turn email.
- Semantic search layer for room type lookup to improve matching of room types to guest requests.
- Support for semantic search layer for policy & static knowledge retrieval.
draftandedited_draftare fed to self-improvement flow.- Support for partial approvals.