mirror of
https://github.com/langchain-ai/agents-from-scratch-ts.git
synced 2026-07-01 21:34:00 -04:00
f2eb51566c17bfedf96491bcd3f7334eec2c8f02
Python Translation To-Do
- prompts
- schemas
- mock tools
- utils
- email assistant
- [Th APR 31 ] email_assistant_hitl
- [ Fri May 1] email_assistant_memory
TypeScript Email Assistant Implementation
This is a vanilla TypeScript project for email assistant workflows using LangChain and LangGraph.
Architecture
- Uses
StateGraphfrom LangGraph to create a multi-step workflow - Leverages
Annotationto track state across the graph nodes - Two main components: triage router + email response agent
Key LangChain/LangGraph Components:
initChatModel: Creates LLM instanceStructuredTool: Base class for tool definitionsBaseMessage,AIMessage,HumanMessage,SystemMessage: Message handlingToolMessage,ToolCall: Tool interaction typesmessagesStateReducer: Manages message state historyStateGraph: Main orchestration frameworkCommand: Directs state transitions in the graph
Workflow Sequence:
triageRouter: Classifies email as respond/ignore/notify- If respond →
response_agent(compiled agent workflow) - Agent workflow:
llmCall: Makes decisions using LLM + bound toolstoolNode: Executes tool calls with error handlingshouldContinue: Determines if more tool calls needed
Email Processing:
- Parses emails with
parseEmail→ author, to, subject, thread - Formats email content with
formatEmailMarkdown - Routes to appropriate handling based on classification
State Management:
AgentStatetracks messages, email input, and classification- Properly typed with TypeScript for complete type safety
- Uses command pattern to transition between states
Project Structure
scripts/: TypeScript scripts to run the email assistantlib/: Utility functions, tools, and shared typeslib/tools/: Tool implementationslib/prompts.ts: Prompt templateslib/schemas.ts: TypeScript/Zod schemaslib/utils.ts: Utility functions
Getting Started
First, install dependencies:
npm install
# or
yarn
# or
pnpm install
Then, run the development script:
npm run dev
# or
yarn dev
# or
pnpm dev
Course outline
BUILD
EVAL
HITL
MEMORY
This is a Next.js project bootstrapped with create-next-app.
Getting Started
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
Description
Languages
Jupyter Notebook
76.3%
TypeScript
23.1%
JavaScript
0.5%