Domain Expert Agent Using the Document System
This example demonstrates a workflow that provides documents to an AI agent for professional analysis. Using legal documents as an example, you can see how the agent refers to the document content to answer questions.
Core Idea: Document + Agent
The core of this workflow is to include external documents in the agent's system prompt:
version: "agentflow/v1"
kind: "WorkflowSpec"
metadata:
name: "Document-based Expert Agent"
description: "A domain expert AI that refers to document content"
version: "0.1.0"
agents:
- id: "lawyer_agent"
inline:
type: "agent"
model: "openai/gpt-4.1-mini"
system_prompt: |
You are a lawyer.
Answer the questions based on the content of the document below.
Please include references in your answer.
Provide your answer in JSON format.
Example:
{
"answer": "The answer is OOO.",
"references": [
"Document1",
"Document2"
]
}
<help>
Use the document name attribute to indicate your references.
</help>
<document name="Genius act">
{{{documents.genius_act.content}}}
</document>
nodes:
start:
type: "agent_task"
agent: "lawyer_agent"
next: "end"
end:
type: "end"
How the Document System Works
The key to utilizing documents in a workflow is the {{{documents.genius_act.content}}}
template syntax:
const documents = {
'genius_act': {
type: 'markdown',
filters: [new RemoveBase64ImageFilter()], // Remove images
content: readFileSync('./docs/Genius act.md', 'utf-8')
}
};
const workflow = new Workflow({
mainWorkflow: workflowYaml,
documents, // Pass documents
responseFilters: [new RemoveMarkdownJsonFilter()] // Clean up JSON response
});
Actual Execution Result
const result = await workflow.ask("미국이 왜 이 법안을 발의했을까?");
Actual Response:
{
"answer": "The primary purpose for the United States to introduce this bill, the GENIUS Act of 2025, is to systematize the regulation of payment stablecoins and ensure their stability. The bill aims to establish clear standards for the issuance and operation of stablecoins to ensure the safety and soundness of the financial system, enhance consumer protection, and manage risks to financial stability.",
"references": [
"Genius act - SECTION 1. Short title.",
"Genius act - SEC. 3. Limitation on who may issue a payment stablecoin.",
"Genius act - SEC. 4. Requirements for issuing payment stablecoins.",
"Genius act - SEC. 6. Supervision and enforcement with respect to subsidiaries of insured depository institutions and Comptroller-regulated entities.",
"Genius act - SEC. 8. Customer protection.",
"Genius act - SEC. 9. Treatment of insolvent payment stablecoin issuers."
]
}
Execution Statistics:
Total execution time: 7.15 seconds
Node execution: start(7087ms) -> end(0ms)
Response filter: Markdown code block removed
Other Use Cases
This document system can be applied to other domains:
Medical Document Analysis
<document name="Clinical Trial Report">
{{{documents.clinical_report.content}}}
</document>
Technical Document Analysis
<document name="API Specification">
{{{documents.api_spec.content}}}
</document>
Contract Review
<document name="Contract">
{{{documents.contract.content}}}
</document>
Key Points
- Document Injection: Include documents in the system prompt using
{{{documents.key.content}}}
syntax. - Filtering: Pre-processing, such as removing Base64 images, is possible.
- Structured Response: Provide answers and reference information in JSON format.
- Domain Expertise: The agent acts as a specialist in a specific field.
This is the essence of Domain Expert Agents using SowonFlow's Document System.