// Slide 23: Middleware -- HumanInTheLoop + PIIRedaction + Summarization // Code slide: cross-cutting hooks attached at agent construction. const ds = require('./design-system'); function createSlide(pres, theme) { const slide = pres.addSlide(); ds.helpers.slideBase(slide, pres, theme); ds.helpers.addHeader(slide, pres, theme, { eyebrow: 'STAGE 1: CHAINS', section: 'Middleware', title: 'Cross-cutting concerns одной строкой', sectionNumber: 1, }); ds.helpers.addCodeBlock(slide, pres, theme, { x: 0.5, y: 1.5, w: 9.0, h: 3.25, language: 'python', filePath: 'examples/middleware.py', code: [ 'from langchain.agents import create_agent', 'from langchain.agents.middleware import (', ' HumanInTheLoopMiddleware,', ' PIIRedactionMiddleware,', ' SummarizationMiddleware,', ')', 'from langchain.tools import tool', '', '@tool', 'def send_email(to: str, body: str) -> str:', ' """Send an email to recipient."""', ' return f"sent to {to}"', '', 'agent = create_agent(', ' model="openai:gpt-4.1",', ' tools=[send_email],', ' middleware=[', ' HumanInTheLoopMiddleware(interrupt_on={"send_email": True}),', ' PIIRedactionMiddleware(redact_emails=True, redact_phones=True),', ' SummarizationMiddleware(trigger=("tokens", 4000)),', ' ],', ')', ].join('\n'), }); // Right-side mini-glossary callouts (left side has code; reuse addCallout below) ds.helpers.addCallout(slide, pres, theme, { x: 0.5, y: 4.85, w: 9.0, h: 0.3, kind: 'warning', text: 'Все три middleware -- встроенные. Custom middleware пишутся как before_model/after_model hooks.', }); ds.helpers.addSourceLine(slide, pres, theme, { source: 'docs.langchain.com/oss/python/langchain/middleware', }); ds.helpers.addPageNumber(slide, pres, theme, 23); } module.exports = { createSlide };