GenAI Workflows
Not all AI applications are agents! In engineering terms, Agents are systems with high freedom and autonomy but low human control. Before moving on to agents, let's explore more controlled uses of LLMs because, in the future, your agents will use them as subsystems.
Questions
- What is not an agent (in our engineering world)?
- What is a Directed Acyclic Graph (DAG)?
- What types of workflows exist?
Steps
According to the emerging consensus in the community (X, Anthropic, OpenAI), agents are systems that operate cyclically until they decide to stop themselves. Thanks to LLMs, an Agent can assess how well it has performed a task and pause execution (e.g., via a ToolCall: ReturnFinalAnswer
call).
Most advanced agents today, in addition to evaluating task completion, also independently plan sub-steps to achieve the goal and loop through each step until it is completed, only then moving on to the next steps.
Therefore, anything that is a DAG - directed acyclic graph - is not an agent.
Briefly about DAG
or
Exception
If the looping is triggered by strict logic, it is considered a workflow, not an agent.
Below you will see the "Summarization of Infinite Text" workflow, which recursively summarizes text until it reaches a text of a certain short length. This is not an agent, but a workflow, even though it has looping.
1. Read this Anthropic article
2. Real-life examples of LLM workflows
Study the examples below. This is important for architectural awareness.
Try to "compile" some pipelines in your head.
We tried to write examples of requests/prompts - read them if something is unclear.
Communication and Support
Email Classifier
Example Input Requests
Email 1:
From: client@example.com
Subject: Payment Issue
Message: "Hello, I paid for the order a few days ago, but the status has not changed. Please help."
Email 2:
From: user2@example.com
Subject: Question about the product
Message: "Good afternoon, please tell me about the features of your application."
System Prompt: Email Classifier
You are a model that classifies incoming emails as 'spam' or 'not_spam'.
You receive the header and body of the email as input.
Output is a single word: 'spam' or 'not_spam'.
System Prompt: Validator (Can LLM answer?)
You are a model that checks whether an LLM can autonomously answer a request.
You receive the body of the email.
If the answer is simple, output 'simple_answer', otherwise 'complex_answer'.
System Prompt: Answer Generation
You are a support assistant. Compose a polite and concise answer to the client based on the text of the email:
\"\"\"{email_body}\"\"\"
Support Request Triage
Example Input Requests
Request 1: "How do I reset my account password?"
Request 2: "I have an error when paying for a subscription, order number #12345."
System Prompt: Intent Classification
You are a model that determines the intent based on the client's message: 'FAQ' or 'technical_support'.
Output is 'FAQ' or 'technical_support'.
System Prompt: LLM FAQ Answer Generation
You are an assistant generating an answer based on the found FAQ.
Input: client request and FAQ content:
\"\"\"Question: {faq_question}
Answer: {faq_answer}\"\"\"
Output is a complete answer to the client.
Document Summarization
Document Summarization Pipeline
Example Input Documents
Document 1: Article about JavaScript (≈ 5,000 tokens)
Document 2: Quarterly Sales Report (≈ 8,000 tokens)
System Prompt: LLM — Summarization of Parts
You are a model for summarizing text fragments.
Your task is to form a short and informative summary (≤ 500 tokens) based on the input fragment (≤ 6000 tokens).
Input: text fragment of the document.
Output: summary of the fragment.
Summarization of Infinite Text
Suppose you can only use an LLM that can maximally accommodate 8000 tokens in its Attention layers. The maximum LLM can generate up to 2000 tokens. (Total: 6000 tokens input, 2000 output)
For example, for a text of 18 megatokens, the algorithm will run in 2 summarization cycles:
- 1 cycle: 18,000 tokens -> 6,000 tokens 1.1. 18,000 tokens -> 3 chunks of 6,000 tokens 1.2. 3 chunks of 6,000 tokens -> 3 summaries of 2,000 tokens 1.3. 3 summaries of 2,000 tokens -> concatenation into 1 summary of 6,000 tokens
- 2 cycle: 6,000 tokens -> 2,000 tokens 2.1. 6,000 tokens -> 1 chunk of 6,000 tokens 2.2. 1 chunk of 6,000 tokens -> 1 summary of 2,000 tokens 2.3. 1 summary of 2,000 tokens -> final summary
Example Input Document
Document: Technical product specification (≈ 400,000 tokens)
System Prompt: LLM — Summarizes each part to 2000 tokens
Summarize the text in 2000 tokens.
Analysis and Processing of Large Text with Manager Logic
Example Input Data
Processing logic: "Find all mentions of the words 'error' and 'exception', count their frequency."
Text: Application logs (≈ 100,000 tokens)
System Prompt: LLM — Processing a text chunk
You are an analytical model. Your task is to form a partial report based on the user's specified logic and the input text chunk.
Input:
- Processing logic: {logic}
- Chunk text: {text}
Output:
- Partial report.
Social Monitoring and Recommendations
Social Media Monitoring
Example Input Requests
Request 1: "Collect the last 100 tweets with the hashtag #ourProduct"
Request 2: "Get posts from Instagram for the last 24 hours mentioning the brand"
Example System Prompt for the "Sentiment Analysis" Step
You are a social media sentiment analysis model. Your task is to classify each post as "Negative", "Neutral" or "Positive".
Input data:
- Post text: {text}
Output data:
- Sentiment: {Negative|Neutral|Positive}
- Brief justification of the classification.
Recommendation System
Example Input Data
User profile:
- ID: 12345
- View history: ["Phone", "Headphones", "Cases"]
- Age: 29
- Interests: technology, music
Example System Prompt for the "Recommendation Generation" Step
You are an LLM-based recommendation system. Your task is to generate five relevant recommendations based on user embeddings and a list of similar products.
Input data:
- User embeddings: {vector}
- List of similar products: [{id, name, embedding}, ...]
Output data:
- JSON array with recommendations:
[
{id: ..., name: ..., reason: ...},
...
]
Code Review and Publication
Automated Code Review
Example Input Requests
Request 1: Pull Request with changes to the app.js file:
```diff
- function add(a, b) { return a + b; }
+ function add(a, b) { return Number(a) + Number(b); }
Request 2: Pull Request deleting unused variables in utils.js:
- const unused = 42;
+ // deleted
</details>
<details>
<summary>System Prompt: LLM — Comment Generation</summary>
```text
You are an assistant for automated code review.
Your task is to:
- detect syntax or logic errors,
- note style guide violations,
- suggest code improvement recommendations,
based on the Pull Request diff.
Input data:
- diff Pull Request: {diff}
Output format (structured output):
[
{file: "app.js", line: 1, comment: "It is recommended to explicitly cast parameters to Number for safe string addition."},
{file: "utils.js", line: 3, comment: "The 'unused' variable is not used - it should be deleted."}
]
Blog Publication
Example Input Requests
Article draft:
"OpenAI introduced a new GPT-4 model. It offers improved text generation, code support, and data analytics capabilities. Some sections of the text can be made smoother and more expressive..."
System Prompt: LLM — Spell Check
You are a model for spell checking texts.
Your task is to find and correct typos and typographical errors.
Input:
- draft text: {draft_text}
Output:
- corrected text without errors.
System Prompt: LLM — Style Improvement
You are a model for stylistic editing of texts.
Your task is to make the text smoother, clearer and more attractive while preserving the original meaning.
Input:
- text after spell checking: {corrected_text}
Output - edited text.
Marketing and Sales
Marketing Campaign Personalization
Example Input Requests
CRM data 1: {id: 101, name: "Anna", age: 28, last_purchases: ["sneakers","t-shirt"], interests: ["sports","travel"]}
CRM data 2: {id: 102, name: "Boris", age: 35, last_purchases: ["smart watch"], interests: ["technology","fitness"]}
System Prompts
LLM: Audience Segmentation
You are a model that segments customers into categories (age, interests, purchase history) based on a list of CRM data.
Input: list of clients [{id, name, age, last_purchases, interests}, ...]
Output - JSON array of segments:
[
{segment_id: 1, criteria: "athletes 25-35", clients: [101, ...]},
...
]
LLM: Message Generation
You are a copywriter assistant creating personalized e-mails for each segment.
Input: segment {segment_id, criteria, clients} and message template.
Output - JSON array of messages:
[
{segment_id: 1, subject: "Special offer for athletes", body: "..."},
...
]
Lead Qualification and Upsale (Sales)
Example Input Requests
Lead 1: {id: "LID123", company: "Acme Corp", budget: 50000, need: "CRM system"}
Lead 2: {id: "LID124", company: "Beta LLC", budget: 150000, need: "sales analytics"}
System Prompts
LLM: Qualification
You are a model that assesses leads for readiness to buy.
Input: lead {id, company, budget, need}
Output - {lead_id, status: "ready"/"not ready", score: number}
LLM: Commercial Offer
You are a sales assistant generating commercial offers.
Input: lead {lead_id, company, need, budget} and CP template.
Output - {lead_id, proposal: "text of commercial offer"}
LLM: Response Analysis
You are a model for analyzing customer feedback.
Input: correspondence {lead_id, messages: [...]}
Output - {lead_id, sentiment: "positive"/"negative"/"neutral"}
LLM: Upsale Generation
You are an upsell assistant forming an additional offer.
Input: lead {lead_id} and interaction history.
Output - {lead_id, upsell_offer: "text of additional offer"}
Operational Processes
Automatic Replenishment of Goods
Example Input Data
{
"sales_data": [
{"product_id": "A1", "date": "2024-06-01", "quantity": 120},
{"product_id": "B2", "date": "2024-06-01", "quantity": 75}
],
"safety_stock": 50
}
System Prompts
LLM: Demand Forecast
You are a demand forecasting model.
Input: array of sales records with fields {product_id, date, quantity}.
Task: based on historical data, predict demand for each product for the next period.
Output: array of objects [{product_id, forecast_quantity}, ...].
LLM: Order Generation
You are an assistant for generating orders to a supplier.
Input: demand forecast [{product_id, forecast_quantity}, ...] and safety stock parameter.
Task: calculate the order quantity to cover the forecast demand plus the reserve.
Output: array of objects [{product_id, order_quantity}, ...].
Document Compliance Check
Example Input Data
Document type: lease agreement
Document text:
"This agreement is concluded between the Landlord and the Tenant...
Article 1. Subject of the agreement...
Article 2. Term of validity..."
System Prompts
LLM: Key Point Extraction
You are a model for extracting key points from legal text.
Input: full text of the document.
Task: highlight article numbers and their brief content.
Output: array of objects [{article: number, summary: text}, ...].
LLM: Rule Compliance Assessment
You are a model for checking document compliance with specified regulations.
Input: array of key points and list of rules.
Task: for each item, determine whether it complies with the rules.
Output: [{article, compliance: "complies"/"does not comply", comments}, ...].
LLM: Report Generation
You are a report preparation assistant.
Input: compliance assessment results.
Task: generate a structured report in markdown with sections "Compliant Items" and "Violations".
Output: markdown text of the report.
HR Processes
Resume Screening (Recruitment)
Input data examples
[
{
"name": "Иван Иванов",
"skills": ["Python", "SQL", "Docker"],
"experience_years": 3,
"education": "Master of Computer Science"
},
{
"name": "Анна Петрова",
"skills": ["Java", "Spring", "Microservices"],
"experience_years": 5,
"education": "Bachelor of IT"
}
]
System prompts
LLM: resume parsing
You are a model for structuring resumes.
Input: resume text.
Task: extract {name, skills, experience_years, education}.
Output: JSON object with candidate fields.
LLM: candidate scoring
You are a model for evaluating resumes based on specified criteria.
Input: object {name, skills, experience_years}.
Criteria: relevance of skills and work experience.
Output: {name, score: number from 0 to 100}.
LLM: schedule interview
You are an interview scheduling assistant.
Input: list of candidates who passed the threshold and available interview slots.
Task: allocate candidates to slots.
Output: [{name, interview_time}, ...].
Onboarding Automation (HR)
Input data examples
{
"name": "Сергей Кузнецов",
"position": "Frontend-разработчик",
"start_date": "2024-07-01"
}
System prompts
LLM: document preparation
You are an HR assistant for preparing corporate documents.
Input: {name, position, start_date}.
Task: generate a list and templates of documents (employment contract, NDA, etc.).
Output: [{document_type, template_text}, ...].
LLM: IT and access instructions
You are a model for generating instructions for setting up the IT environment.
Input: employee's position.
Task: create a checklist for creating accounts and setting up software.
Output: a list of checklist items.
LLM: training plan
You are an assistant for training new employees.
Input: position.
Task: develop a step-by-step training plan with modules and deadlines.
Output: [{module, duration_days}, ...].
LLM: collect feedback
You are a model for generating a feedback questionnaire.
Input: list of onboarding stages.
Task: formulate questions for each stage.
Output: [{stage, questions: [...]}, ...].
LLM: HR notification
You are an assistant for notifying HR of the results.
Input: feedback results.
Task: compose a brief message with key findings.
Output: notification text.
DevOps
CICD pipeline monitoring
Input data examples
Commit: {id: "abc123", author: "ivan", timestamp: "2024-06-15T10:23:00Z"}
Build logs: "ERROR: Module not found: 'utils.js'"
System prompt examples
LLM: log analysis
You are a model for analyzing CI logs. Input: build log text. Task: find the cause of the error and suggest a solution. Output: {error_type, message, recommendation}.
LLM: results analysis
You are a model for analyzing autotest results. Input: test runner output. Task: identify failed tests and describe the problem. Output: [{test_name, status: "fail"/"pass", log}].
Autotests: generation and analysis
Input data examples
Code changes: diff function sum(a, b)
Test results: 3 passed, 1 failed (test_sum.js)
System prompt examples
LLM: autotest generation
You are an autotest generation assistant. Input: code diff. Task: generate unit tests on Jest for new or modified functions. Output: test code.
LLM: results analysis
You are a model for analyzing test results. Input: test runner output. Task: highlight failed tests and suggest fix options. Output: [{test_name, status, suggestion}].
Other cases
Quiz generation for training
Input data examples
Training material: "HTTP basics: GET/POST methods, status codes"
System prompt examples
LLM: question generation
You are a model for generating training questions. Input: material text. Task: formulate 5 questions of different types (open-ended, multiple choice). Output: [{question, type}].
LLM: quality check
You are a model for evaluating the quality of questions. Input: list of questions. Task: check the correctness of formulations and complexity. Output: [{question, ok: true/false, comment}].
Expense report automation
Input data examples
{
"transactions": [
{"id": "T1", "amount": 250},
{"id": "T2", "amount": 75}
]
}
System prompt examples
LLM: expense extraction
You are a model for extracting expense data. Input: array of transactions. Task: return a list of {id, amount}.
LLM: categorization
You are a model for classifying expenses. Input: list of {id, amount}. Task: assign a category from the list. Output: [{id, category}].
Personal travel planner
Input data examples
{
"destination": "Барселона",
"dates": ["2024-07-01", "2024-07-07"],
"preferences": ["музеи", "пляж"]
}
System prompt examples
LLM: route plan
You are a travel planning assistant. Input: trip parameters. Task: suggest a route by day. Output: [{day, activities}].
LLM: booking generation
You are a model for generating bookings. Input: route. Task: generate data for hotel and transport bookings. Output: [{service, details}].
LLM: plan formatting
You are a plan formatting assistant. Input: booking data and route. Task: assemble a single document with a schedule. Output: markdown.
Request routing to four departments
Examples of incoming requests
Request 1: "Hello! I want to know about new tariffs."
Request 2: "I can't pay the bill, the payment is declined."
Request 3: "How to connect international roaming?"
Request 4: "Where can I find the offer agreement?"
System prompt: LLM routing
You are a model for routing incoming customer requests.
Input data:
- Customer request text: {request}
Task: determine the direction of request processing: one of the values "Sales", "Technical support", "Billing", "General questions".
Output: a string with one of the specified values.
System prompt: LLM request processing
You are a model for processing customer requests in the {direction} direction.
Input data:
- Customer request text: {request}
Task: generate a detailed and polite response to the request in accordance with the specifics of the direction.
Output: text response to the client.
Web3 workflows examples
Minting and listing NFT
Input data examples
{
"name": "CryptoKitty #2024",
"description": "Exclusive NFT with animated kitty",
"image": "https://example.com/cat.gif",
"attributes": [
{ "trait_type": "rarity", "value": "epic" },
{ "trait_type": "background", "value": "galaxy" }
]
}
System prompts
LLM: JSON metadata generation
You are a model for generating NFT JSON metadata in ERC-721 format.
Input: {name, description, image, attributes}.
Output: JSON object without unnecessary comments.
LLM: listing description generation
You are a model for writing selling NFT descriptions.
Input: NFT JSON metadata.
Task: generate a short (2–3 sentences), catchy description.
Output: plain text.
Token swap on DEX
Input request examples
Request 1: "Swap 1.5 ETH to DAI at the best rate."
Request 2: "Swap 1000 USDC to USDT with minimal fees."
System prompts
LLM: swap parameter parsing
You are a model for extracting swap parameters from a text request.
Input: request text.
Task: return JSON {from_token, to_token, amount}.
LLM: optimal route selection
You are a model for selecting the optimal swap route on DEX.
Input: JSON {from_token, to_token, amount}.
Task: suggest an exchange path through pools, minimizing slippage.
Output: JSON {route, estimated_gas}.
Creating a proposal in DAO
Input request examples
Idea 1: "Suggest increasing the liquidity pool by 5% transaction fee."
Idea 2: "Implement a reward program for active DAO participants."
System prompts
LLM: proposal text draft
You are a model for transforming an idea into a formal DAO proposal.
Input: idea text.
Task: generate JSON {title, description}.
LLM: formatting to DAO requirements
You are a model for formatting a draft according to the DAO template.
Input: JSON {title, description}.
Requirements: title up to 100 characters, description up to 1000 characters.
Output: JSON {title, description}.
LLM: voting results summary
You are a model for creating a final voting summary.
Input: list of votes [{voter, vote}].
Task: calculate the results and formulate a conclusion.
Output: text summary.
Automated smart contract audit
Input data examples
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleToken {
mapping(address => uint256) public balances;
function mint(address to, uint256 amount) public {
balances[to] += amount;
}
}
System prompts
LLM: security analysis
You are a model for smart contract security analysis.
Input: contract source code.
Task: identify vulnerabilities (overflow, reentrancy, etc.) and provide recommendations.
Output: JSON [{issue, severity, recommendation}].
LLM: vulnerability report generation
You are a model for compiling a report based on vulnerability analysis.
Input: security analysis results.
Task: write a detailed markdown report describing each problem and recommendations.
Output: markdown.
In business projects in the field of production, workflows often consist of 20+ nodes, interspersed with API integrations, strict logic, LLM sub-workflows, and AI Agents. And sometimes they can reach up to 100 nodes.
2. Advanced routing in LLM Workflows
Extra Steps
E1. langchain
LangChain is a library for building and using LLM-workflows. It is old but well-documented and has a large community.
Browse what entities are in LangChain: https://python.langchain.com/docs/concepts/
Example of the simplest langchain code.
E2. Patterns meta-understanding
- https://refactoring.guru/design-patterns/chain-of-responsibility
- https://refactoring.guru/design-patterns/command
Deprecated content
Now we know...
In this lesson, we learned the basics of LLM workflows: we analyzed the engineering definition of agents and the difference between cyclic systems and DAG structures, studied practical examples, design patterns, and delved deeper into routing.
However, you should not be too strict with other people in definitions. Understanding the difference between agents, chatbots, and workflows is only necessary for engineers to avoid miscommunication.
Managers, clients, and investors do not need to understand this difference. Leave them the opportunity to call everything as they see fit: AI Agents, "neural networks", "artificial intelligence".
Exercises
- If there is looping in your system, is it an agent or a workflow?
- What branching patterns do you remember?
- *For those who have completed the module on algorithms for GenAI:
- think about how you can combine algorithmic approaches and LLM workflows
- Design on paper:
- A system for automatically responding to support requests for a mobile food delivery application
- A workflow for auto-responding to messages in your messenger from an unknown contact
- A system for automatically creating posts for your blog
- A system for scoring a candidate for a vacancy, then a system for comparing several candidates at once