Skip to content
LangChain

Asystent email z LangChain

Zbuduj asystenta email AI, który przeszukuje skrzynkę, tworzy odpowiedzi i zarządza przepływami email — z LangChain.

emailautomationproductivityassistant

Działający kod

LangChain
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
@tool
def search_emails(query: str, limit: int = 5) -> str:
"""Search the inbox for emails matching a query."""
results = email_client.search(query, max_results=limit)
return "\n\n".join(
f"From: {e.sender}\nSubject: {e.subject}\nDate: {e.date}\nPreview: {e.body[:200]}"
for e in results
)
@tool
def draft_email(to: str, subject: str, body: str) -> str:
"""Create an email draft."""
draft_id = email_client.create_draft(to=to, subject=subject, body=body)
return f"Draft created (ID: {draft_id}). Review before sending."
model = ChatOpenAI(model="gpt-4o")
model_with_tools = model.bind_tools([search_emails, draft_email])
response = model_with_tools.invoke([
("system", "You are an email assistant. Search emails to find context, then help draft professional replies. Always create drafts — never send directly."),
("user", "Find the latest email from the marketing team and draft a reply confirming the deadline"),
])

Krok po kroku

1

Zainstaluj zależności

Zainstaluj LangChain i wymagane narzędzia do tego przypadku użycia.

2

Zdefiniuj narzędzia

Stwórz specyficzne dla domeny funkcje narzędzi, których agent będzie używał do interakcji z zewnętrznymi serwisami.

3

Stwórz agenta i uruchom

Zainicjalizuj agenta LangChain z narzędziami, ustaw prompt systemowy i wykonaj zapytanie.

Gotowy do budowania z LangChain?

Wygeneruj gotowy do produkcji projekt z LangChain — FastAPI + Next.js, autoryzacja, streaming i więcej.

Rozpocznij

Gotowy, żeby zbudować swojego pierwszego agenta AI?

Open-source'owe narzędzia, sprawdzone wzorce, zero boilerplate'u. Skonfiguruj swój stos i wyślij w minuty — nie miesiące.