unique-swot 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unique_swot-0.1.0/LICENSE +1 -0
- unique_swot-0.1.0/PKG-INFO +215 -0
- unique_swot-0.1.0/README.md +195 -0
- unique_swot-0.1.0/pyproject.toml +36 -0
- unique_swot-0.1.0/unique_swot/__init__.py +7 -0
- unique_swot-0.1.0/unique_swot/config.py +53 -0
- unique_swot-0.1.0/unique_swot/docs/swot_generator_architecture.md +89 -0
- unique_swot-0.1.0/unique_swot/docs/swot_overall_architecture.md +186 -0
- unique_swot-0.1.0/unique_swot/service.py +231 -0
- unique_swot-0.1.0/unique_swot/services/citations.py +306 -0
- unique_swot-0.1.0/unique_swot/services/collection/__init__.py +6 -0
- unique_swot-0.1.0/unique_swot/services/collection/base.py +128 -0
- unique_swot-0.1.0/unique_swot/services/collection/registry.py +54 -0
- unique_swot-0.1.0/unique_swot/services/collection/schema.py +32 -0
- unique_swot-0.1.0/unique_swot/services/collection/sources/__init__.py +7 -0
- unique_swot-0.1.0/unique_swot/services/collection/sources/earnings_call.py +13 -0
- unique_swot-0.1.0/unique_swot/services/collection/sources/knowledge_base.py +96 -0
- unique_swot-0.1.0/unique_swot/services/collection/sources/web.py +13 -0
- unique_swot-0.1.0/unique_swot/services/executor.py +252 -0
- unique_swot-0.1.0/unique_swot/services/generation/__init__.py +92 -0
- unique_swot-0.1.0/unique_swot/services/generation/batch_processor.py +157 -0
- unique_swot-0.1.0/unique_swot/services/generation/config.py +54 -0
- unique_swot-0.1.0/unique_swot/services/generation/contexts.py +73 -0
- unique_swot-0.1.0/unique_swot/services/generation/generator.py +162 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/__init__.py +23 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/opportunities.py +43 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/protocol.py +27 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/strengths.py +50 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/threats.py +48 -0
- unique_swot-0.1.0/unique_swot/services/generation/models/weaknesses.py +50 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/__init__.py +20 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/extraction/base_template.j2 +29 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/extraction/components.py +237 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/extraction/config.py +30 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/extraction/template.py +105 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/summarization/base_template.j2 +102 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/summarization/components.py +151 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/summarization/config.py +30 -0
- unique_swot-0.1.0/unique_swot/services/generation/prompts/summarization/template.py +99 -0
- unique_swot-0.1.0/unique_swot/services/generation/utils/__init__.py +22 -0
- unique_swot-0.1.0/unique_swot/services/generation/utils/chunk_template.j2 +7 -0
- unique_swot-0.1.0/unique_swot/services/memory/__init__.py +3 -0
- unique_swot-0.1.0/unique_swot/services/memory/base.py +105 -0
- unique_swot-0.1.0/unique_swot/services/notifier.py +189 -0
- unique_swot-0.1.0/unique_swot/services/report/__init__.py +10 -0
- unique_swot-0.1.0/unique_swot/services/report/config.py +38 -0
- unique_swot-0.1.0/unique_swot/services/report/delivery.py +143 -0
- unique_swot-0.1.0/unique_swot/services/report/docx.py +18 -0
- unique_swot-0.1.0/unique_swot/services/report/report_template.j2 +32 -0
- unique_swot-0.1.0/unique_swot/services/schemas.py +141 -0
- unique_swot-0.1.0/unique_swot/tests/README.md +192 -0
- unique_swot-0.1.0/unique_swot/tests/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/conftest.py +157 -0
- unique_swot-0.1.0/unique_swot/tests/services/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/services/collection/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/services/collection/test_base.py +144 -0
- unique_swot-0.1.0/unique_swot/tests/services/collection/test_registry.py +173 -0
- unique_swot-0.1.0/unique_swot/tests/services/collection/test_schema.py +161 -0
- unique_swot-0.1.0/unique_swot/tests/services/generation/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/services/generation/test_batch_processor.py +504 -0
- unique_swot-0.1.0/unique_swot/tests/services/generation/test_config.py +61 -0
- unique_swot-0.1.0/unique_swot/tests/services/generation/test_generator.py +548 -0
- unique_swot-0.1.0/unique_swot/tests/services/memory/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/services/memory/test_base.py +254 -0
- unique_swot-0.1.0/unique_swot/tests/services/report/__init__.py +1 -0
- unique_swot-0.1.0/unique_swot/tests/services/report/test_delivery.py +492 -0
- unique_swot-0.1.0/unique_swot/tests/services/report/test_docx.py +253 -0
- unique_swot-0.1.0/unique_swot/tests/services/report/test_report.py +223 -0
- unique_swot-0.1.0/unique_swot/tests/services/test_citations.py +310 -0
- unique_swot-0.1.0/unique_swot/tests/services/test_executor.py +262 -0
- unique_swot-0.1.0/unique_swot/tests/services/test_notifier.py +314 -0
- unique_swot-0.1.0/unique_swot/tests/services/test_schemas.py +211 -0
- unique_swot-0.1.0/unique_swot/tests/test_config.py +77 -0
- unique_swot-0.1.0/unique_swot/tests/test_service.py +218 -0
- unique_swot-0.1.0/unique_swot/utils.py +6 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`unique_swot` is covered by the [`Unique License v1`](https://github.com/Unique-AG/license/releases/tag/unique-license.v1), unless the/a header or a nested LICENSE specifies another license.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: unique-swot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unique Swot package is a tool that for conducting a swot analysis based on internal and external documents
|
|
5
|
+
License: Proprietary
|
|
6
|
+
Author: Rami Azouz
|
|
7
|
+
Author-email: rami.ext@unique.ch
|
|
8
|
+
Requires-Python: >=3.12,<4.0
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Requires-Dist: beautifulsoup4 (>=4.14.2,<5.0.0)
|
|
13
|
+
Requires-Dist: jinja2 (>=3.1.0,<4.0.0)
|
|
14
|
+
Requires-Dist: pydantic (>=2.8.2,<3.0.0)
|
|
15
|
+
Requires-Dist: python-docx (>=1.2.0,<2.0.0)
|
|
16
|
+
Requires-Dist: ruff (>=0.11.7,<0.12.0)
|
|
17
|
+
Requires-Dist: unique-toolkit (>=1.22.1,<2.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# SWOT Analysis Tool
|
|
21
|
+
|
|
22
|
+
A sophisticated AI-powered tool for generating comprehensive SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis reports based on internal documents, earnings calls, and external web resources.
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
The SWOT Analysis Tool is an agentic tool built on the Unique Toolkit framework that automatically analyzes multiple data sources to produce structured, well-cited SWOT analysis reports. It leverages large language models with structured output to extract insights and generate professional-grade analysis documents.
|
|
27
|
+
|
|
28
|
+
## Architecture
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
## Project Structure
|
|
33
|
+
```
|
|
34
|
+
unique_swot/
|
|
35
|
+
├── service.py # Main SwotAnalysisTool
|
|
36
|
+
├── services/
|
|
37
|
+
│ ├── citations.py # Citation management
|
|
38
|
+
│ ├── executor.py # Execution orchestration
|
|
39
|
+
│ ├── notifier.py # Progress notifications
|
|
40
|
+
│ ├── collection/ # Source collection
|
|
41
|
+
│ ├── generation/ # LLM-based generation
|
|
42
|
+
│ ├── memory/ # State management
|
|
43
|
+
│ └── report/ # Report rendering
|
|
44
|
+
├── tests/ # Comprehensive test suite
|
|
45
|
+
└── docs/ # Architecture documentation
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## How It Works
|
|
49
|
+
|
|
50
|
+
### 1. **Plan Reception & Validation**
|
|
51
|
+
The tool receives a SWOT plan specifying which components to analyze (Strengths, Weaknesses, Opportunities, Threats) and the analysis objective. Each component can be set to:
|
|
52
|
+
- `GENERATE` - Create new analysis from sources
|
|
53
|
+
- `MODIFY` - Update existing analysis with new information
|
|
54
|
+
- `NOT_REQUESTED` - Skip this component
|
|
55
|
+
|
|
56
|
+
### 2. **Multi-Source Data Collection**
|
|
57
|
+
The tool collects relevant information from multiple sources:
|
|
58
|
+
- **Knowledge Base**: Internal documents filtered by metadata
|
|
59
|
+
- **Earnings Calls**: Financial earnings call transcripts
|
|
60
|
+
- **Web Sources**: External web research and articles
|
|
61
|
+
|
|
62
|
+
All collected content is registered in a central registry with unique identifiers for citation tracking.
|
|
63
|
+
|
|
64
|
+
### 3. **Two-Phase Generation Process**
|
|
65
|
+
|
|
66
|
+
For each requested SWOT component:
|
|
67
|
+
|
|
68
|
+
#### Phase 1: Extraction
|
|
69
|
+
- Sources are split into manageable batches based on token limits
|
|
70
|
+
- Each batch is processed by the language model with structured output enforcement
|
|
71
|
+
- The LLM extracts specific SWOT items (e.g., individual strengths) with reasoning
|
|
72
|
+
- Extracted items include citation placeholders linking back to source chunks
|
|
73
|
+
- Results from all batches are aggregated into a structured model
|
|
74
|
+
|
|
75
|
+
#### Phase 2: Summarization
|
|
76
|
+
- The aggregated extraction results are synthesized
|
|
77
|
+
- The LLM generates a coherent narrative summary
|
|
78
|
+
- The summary maintains all citation references
|
|
79
|
+
- Output is formatted with proper structure and citations
|
|
80
|
+
|
|
81
|
+
### 4. **Citation Management**
|
|
82
|
+
The tool implements a sophisticated dual-citation system:
|
|
83
|
+
|
|
84
|
+
- **Inline Citations**: `[bullet_chunk_X]` → Converted to `[1]`, `[2]`, etc.
|
|
85
|
+
- **Consolidated References**: `[chunk_X]` → Expanded to `[1] [Document Title: page 5]`
|
|
86
|
+
|
|
87
|
+
This ensures every claim in the report is traceable back to its source material.
|
|
88
|
+
|
|
89
|
+
### 5. **Report Delivery**
|
|
90
|
+
|
|
91
|
+
The final report can be delivered in two formats:
|
|
92
|
+
|
|
93
|
+
**DOCX Mode** (Document):
|
|
94
|
+
- Markdown converted to professional Word document
|
|
95
|
+
- Full citations with document titles and page numbers
|
|
96
|
+
- Uploaded as downloadable attachment
|
|
97
|
+
|
|
98
|
+
**Chat Mode** (Markdown):
|
|
99
|
+
- Rich markdown formatting displayed in chat
|
|
100
|
+
- Inline superscript citations
|
|
101
|
+
- Clickable references to source documents
|
|
102
|
+
|
|
103
|
+
### 6. **Memory & Caching**
|
|
104
|
+
- Extraction results are cached in memory for potential modifications
|
|
105
|
+
- Content chunk registry persisted for citation lookup
|
|
106
|
+
- Supports iterative refinement of analysis
|
|
107
|
+
|
|
108
|
+
## Key Features
|
|
109
|
+
|
|
110
|
+
### 🎯 Comprehensive Analysis
|
|
111
|
+
- Analyzes all four SWOT dimensions
|
|
112
|
+
- Processes multiple sources simultaneously
|
|
113
|
+
- Maintains context across large document sets
|
|
114
|
+
|
|
115
|
+
### 📊 Intelligent Batch Processing
|
|
116
|
+
- Automatically splits sources based on token limits
|
|
117
|
+
- Processes batches in parallel where possible (planned but not supported yet)
|
|
118
|
+
- Handles sources of any size
|
|
119
|
+
|
|
120
|
+
### 🔗 Advanced Citation System
|
|
121
|
+
- Every point backed by source references
|
|
122
|
+
- Dual-level citation (inline + consolidated)
|
|
123
|
+
- Traceable to specific pages and documents
|
|
124
|
+
|
|
125
|
+
### 📈 Real-Time Progress Tracking
|
|
126
|
+
- Step-by-step progress updates
|
|
127
|
+
- Percentage completion calculation
|
|
128
|
+
- Detailed execution logs
|
|
129
|
+
|
|
130
|
+
### 💾 State Management
|
|
131
|
+
- Caches extraction results for modifications
|
|
132
|
+
- Persistent storage in Knowledge Base
|
|
133
|
+
- Quick lookups via Short-Term Memory
|
|
134
|
+
|
|
135
|
+
### 🎨 Multiple Output Formats
|
|
136
|
+
- Professional DOCX reports
|
|
137
|
+
- Rich markdown for chat
|
|
138
|
+
- Customizable templates
|
|
139
|
+
|
|
140
|
+
### 🛡️ Robust Error Handling
|
|
141
|
+
- Graceful degradation on failures
|
|
142
|
+
- Automatic retry logic
|
|
143
|
+
- Detailed error logging
|
|
144
|
+
|
|
145
|
+
## Workflow Example
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
User Request → SWOT Plan
|
|
149
|
+
↓
|
|
150
|
+
Source Collection (KB + Earnings + Web)
|
|
151
|
+
↓
|
|
152
|
+
For Each Component (Strengths, Weaknesses, Opportunities, Threats):
|
|
153
|
+
├── Split Sources into Batches
|
|
154
|
+
├── Extract SWOT Items from Each Batch (LLM)
|
|
155
|
+
├── Aggregate Extraction Results
|
|
156
|
+
├── Generate Summary (LLM)
|
|
157
|
+
└── Save to Memory
|
|
158
|
+
↓
|
|
159
|
+
Format Citations
|
|
160
|
+
↓
|
|
161
|
+
Render Report (DOCX or Markdown)
|
|
162
|
+
↓
|
|
163
|
+
Deliver to User
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Core Services
|
|
167
|
+
|
|
168
|
+
| Service | Responsibility |
|
|
169
|
+
|---------|---------------|
|
|
170
|
+
| **SwotAnalysisTool** | Main orchestrator, validates plans, manages workflow |
|
|
171
|
+
| **SourceCollectionManager** | Collects data from KB, earnings calls, and web |
|
|
172
|
+
| **SWOTExecutionManager** | Executes analysis for each SWOT component |
|
|
173
|
+
| **BatchProcessor** | Manages batch processing with token limits |
|
|
174
|
+
| **CitationManager** | Tracks and formats citations |
|
|
175
|
+
| **MemoryService** | Persists state and caches results |
|
|
176
|
+
| **ReportDeliveryService** | Renders and delivers final reports |
|
|
177
|
+
| **ProgressNotifier** | Provides real-time progress updates |
|
|
178
|
+
|
|
179
|
+
## Configuration
|
|
180
|
+
|
|
181
|
+
The tool is configured via `SwotAnalysisToolConfig` which includes:
|
|
182
|
+
- Report generation settings (batch size, token limits)
|
|
183
|
+
- Language model configuration
|
|
184
|
+
- Prompt templates for extraction and summarization
|
|
185
|
+
- Report rendering preferences (DOCX vs Chat)
|
|
186
|
+
- Cache scope for state management
|
|
187
|
+
|
|
188
|
+
## Technology Stack
|
|
189
|
+
|
|
190
|
+
- **Framework**: Unique Toolkit (Python)
|
|
191
|
+
- **Validation**: Pydantic models with strict typing
|
|
192
|
+
- **LLM Integration**: Structured output with schema enforcement
|
|
193
|
+
- **Storage**: Knowledge Base for persistence, Short-Term Memory for caching
|
|
194
|
+
- **Templating**: Jinja2 for report templates
|
|
195
|
+
- **Document Processing**: DOCX generation, Markdown rendering
|
|
196
|
+
- **Progress Tracking**: Real-time message execution updates
|
|
197
|
+
|
|
198
|
+
## Use Cases
|
|
199
|
+
|
|
200
|
+
- **Strategic Planning**: Generate comprehensive SWOT analyses for business strategy
|
|
201
|
+
- **Market Analysis**: Analyze market position based on multiple data sources
|
|
202
|
+
- **Competitive Intelligence**: Assess strengths and weaknesses vs competitors
|
|
203
|
+
- **Investment Research**: Evaluate opportunities and threats for investments
|
|
204
|
+
- **Due Diligence**: Comprehensive analysis for M&A or partnerships
|
|
205
|
+
|
|
206
|
+
## Output Quality
|
|
207
|
+
|
|
208
|
+
The tool produces high-quality analysis by:
|
|
209
|
+
- Using structured output to enforce consistency
|
|
210
|
+
- Extracting before summarizing for thorough coverage
|
|
211
|
+
- Maintaining citation integrity throughout the pipeline
|
|
212
|
+
- Validating all outputs against Pydantic schemas
|
|
213
|
+
- Applying domain-specific prompt engineering
|
|
214
|
+
|
|
215
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SWOT Analysis Tool
|
|
2
|
+
|
|
3
|
+
A sophisticated AI-powered tool for generating comprehensive SWOT (Strengths, Weaknesses, Opportunities, Threats) analysis reports based on internal documents, earnings calls, and external web resources.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The SWOT Analysis Tool is an agentic tool built on the Unique Toolkit framework that automatically analyzes multiple data sources to produce structured, well-cited SWOT analysis reports. It leverages large language models with structured output to extract insights and generate professional-grade analysis documents.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Project Structure
|
|
14
|
+
```
|
|
15
|
+
unique_swot/
|
|
16
|
+
├── service.py # Main SwotAnalysisTool
|
|
17
|
+
├── services/
|
|
18
|
+
│ ├── citations.py # Citation management
|
|
19
|
+
│ ├── executor.py # Execution orchestration
|
|
20
|
+
│ ├── notifier.py # Progress notifications
|
|
21
|
+
│ ├── collection/ # Source collection
|
|
22
|
+
│ ├── generation/ # LLM-based generation
|
|
23
|
+
│ ├── memory/ # State management
|
|
24
|
+
│ └── report/ # Report rendering
|
|
25
|
+
├── tests/ # Comprehensive test suite
|
|
26
|
+
└── docs/ # Architecture documentation
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## How It Works
|
|
30
|
+
|
|
31
|
+
### 1. **Plan Reception & Validation**
|
|
32
|
+
The tool receives a SWOT plan specifying which components to analyze (Strengths, Weaknesses, Opportunities, Threats) and the analysis objective. Each component can be set to:
|
|
33
|
+
- `GENERATE` - Create new analysis from sources
|
|
34
|
+
- `MODIFY` - Update existing analysis with new information
|
|
35
|
+
- `NOT_REQUESTED` - Skip this component
|
|
36
|
+
|
|
37
|
+
### 2. **Multi-Source Data Collection**
|
|
38
|
+
The tool collects relevant information from multiple sources:
|
|
39
|
+
- **Knowledge Base**: Internal documents filtered by metadata
|
|
40
|
+
- **Earnings Calls**: Financial earnings call transcripts
|
|
41
|
+
- **Web Sources**: External web research and articles
|
|
42
|
+
|
|
43
|
+
All collected content is registered in a central registry with unique identifiers for citation tracking.
|
|
44
|
+
|
|
45
|
+
### 3. **Two-Phase Generation Process**
|
|
46
|
+
|
|
47
|
+
For each requested SWOT component:
|
|
48
|
+
|
|
49
|
+
#### Phase 1: Extraction
|
|
50
|
+
- Sources are split into manageable batches based on token limits
|
|
51
|
+
- Each batch is processed by the language model with structured output enforcement
|
|
52
|
+
- The LLM extracts specific SWOT items (e.g., individual strengths) with reasoning
|
|
53
|
+
- Extracted items include citation placeholders linking back to source chunks
|
|
54
|
+
- Results from all batches are aggregated into a structured model
|
|
55
|
+
|
|
56
|
+
#### Phase 2: Summarization
|
|
57
|
+
- The aggregated extraction results are synthesized
|
|
58
|
+
- The LLM generates a coherent narrative summary
|
|
59
|
+
- The summary maintains all citation references
|
|
60
|
+
- Output is formatted with proper structure and citations
|
|
61
|
+
|
|
62
|
+
### 4. **Citation Management**
|
|
63
|
+
The tool implements a sophisticated dual-citation system:
|
|
64
|
+
|
|
65
|
+
- **Inline Citations**: `[bullet_chunk_X]` → Converted to `[1]`, `[2]`, etc.
|
|
66
|
+
- **Consolidated References**: `[chunk_X]` → Expanded to `[1] [Document Title: page 5]`
|
|
67
|
+
|
|
68
|
+
This ensures every claim in the report is traceable back to its source material.
|
|
69
|
+
|
|
70
|
+
### 5. **Report Delivery**
|
|
71
|
+
|
|
72
|
+
The final report can be delivered in two formats:
|
|
73
|
+
|
|
74
|
+
**DOCX Mode** (Document):
|
|
75
|
+
- Markdown converted to professional Word document
|
|
76
|
+
- Full citations with document titles and page numbers
|
|
77
|
+
- Uploaded as downloadable attachment
|
|
78
|
+
|
|
79
|
+
**Chat Mode** (Markdown):
|
|
80
|
+
- Rich markdown formatting displayed in chat
|
|
81
|
+
- Inline superscript citations
|
|
82
|
+
- Clickable references to source documents
|
|
83
|
+
|
|
84
|
+
### 6. **Memory & Caching**
|
|
85
|
+
- Extraction results are cached in memory for potential modifications
|
|
86
|
+
- Content chunk registry persisted for citation lookup
|
|
87
|
+
- Supports iterative refinement of analysis
|
|
88
|
+
|
|
89
|
+
## Key Features
|
|
90
|
+
|
|
91
|
+
### 🎯 Comprehensive Analysis
|
|
92
|
+
- Analyzes all four SWOT dimensions
|
|
93
|
+
- Processes multiple sources simultaneously
|
|
94
|
+
- Maintains context across large document sets
|
|
95
|
+
|
|
96
|
+
### 📊 Intelligent Batch Processing
|
|
97
|
+
- Automatically splits sources based on token limits
|
|
98
|
+
- Processes batches in parallel where possible (planned but not supported yet)
|
|
99
|
+
- Handles sources of any size
|
|
100
|
+
|
|
101
|
+
### 🔗 Advanced Citation System
|
|
102
|
+
- Every point backed by source references
|
|
103
|
+
- Dual-level citation (inline + consolidated)
|
|
104
|
+
- Traceable to specific pages and documents
|
|
105
|
+
|
|
106
|
+
### 📈 Real-Time Progress Tracking
|
|
107
|
+
- Step-by-step progress updates
|
|
108
|
+
- Percentage completion calculation
|
|
109
|
+
- Detailed execution logs
|
|
110
|
+
|
|
111
|
+
### 💾 State Management
|
|
112
|
+
- Caches extraction results for modifications
|
|
113
|
+
- Persistent storage in Knowledge Base
|
|
114
|
+
- Quick lookups via Short-Term Memory
|
|
115
|
+
|
|
116
|
+
### 🎨 Multiple Output Formats
|
|
117
|
+
- Professional DOCX reports
|
|
118
|
+
- Rich markdown for chat
|
|
119
|
+
- Customizable templates
|
|
120
|
+
|
|
121
|
+
### 🛡️ Robust Error Handling
|
|
122
|
+
- Graceful degradation on failures
|
|
123
|
+
- Automatic retry logic
|
|
124
|
+
- Detailed error logging
|
|
125
|
+
|
|
126
|
+
## Workflow Example
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
User Request → SWOT Plan
|
|
130
|
+
↓
|
|
131
|
+
Source Collection (KB + Earnings + Web)
|
|
132
|
+
↓
|
|
133
|
+
For Each Component (Strengths, Weaknesses, Opportunities, Threats):
|
|
134
|
+
├── Split Sources into Batches
|
|
135
|
+
├── Extract SWOT Items from Each Batch (LLM)
|
|
136
|
+
├── Aggregate Extraction Results
|
|
137
|
+
├── Generate Summary (LLM)
|
|
138
|
+
└── Save to Memory
|
|
139
|
+
↓
|
|
140
|
+
Format Citations
|
|
141
|
+
↓
|
|
142
|
+
Render Report (DOCX or Markdown)
|
|
143
|
+
↓
|
|
144
|
+
Deliver to User
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Core Services
|
|
148
|
+
|
|
149
|
+
| Service | Responsibility |
|
|
150
|
+
|---------|---------------|
|
|
151
|
+
| **SwotAnalysisTool** | Main orchestrator, validates plans, manages workflow |
|
|
152
|
+
| **SourceCollectionManager** | Collects data from KB, earnings calls, and web |
|
|
153
|
+
| **SWOTExecutionManager** | Executes analysis for each SWOT component |
|
|
154
|
+
| **BatchProcessor** | Manages batch processing with token limits |
|
|
155
|
+
| **CitationManager** | Tracks and formats citations |
|
|
156
|
+
| **MemoryService** | Persists state and caches results |
|
|
157
|
+
| **ReportDeliveryService** | Renders and delivers final reports |
|
|
158
|
+
| **ProgressNotifier** | Provides real-time progress updates |
|
|
159
|
+
|
|
160
|
+
## Configuration
|
|
161
|
+
|
|
162
|
+
The tool is configured via `SwotAnalysisToolConfig` which includes:
|
|
163
|
+
- Report generation settings (batch size, token limits)
|
|
164
|
+
- Language model configuration
|
|
165
|
+
- Prompt templates for extraction and summarization
|
|
166
|
+
- Report rendering preferences (DOCX vs Chat)
|
|
167
|
+
- Cache scope for state management
|
|
168
|
+
|
|
169
|
+
## Technology Stack
|
|
170
|
+
|
|
171
|
+
- **Framework**: Unique Toolkit (Python)
|
|
172
|
+
- **Validation**: Pydantic models with strict typing
|
|
173
|
+
- **LLM Integration**: Structured output with schema enforcement
|
|
174
|
+
- **Storage**: Knowledge Base for persistence, Short-Term Memory for caching
|
|
175
|
+
- **Templating**: Jinja2 for report templates
|
|
176
|
+
- **Document Processing**: DOCX generation, Markdown rendering
|
|
177
|
+
- **Progress Tracking**: Real-time message execution updates
|
|
178
|
+
|
|
179
|
+
## Use Cases
|
|
180
|
+
|
|
181
|
+
- **Strategic Planning**: Generate comprehensive SWOT analyses for business strategy
|
|
182
|
+
- **Market Analysis**: Analyze market position based on multiple data sources
|
|
183
|
+
- **Competitive Intelligence**: Assess strengths and weaknesses vs competitors
|
|
184
|
+
- **Investment Research**: Evaluate opportunities and threats for investments
|
|
185
|
+
- **Due Diligence**: Comprehensive analysis for M&A or partnerships
|
|
186
|
+
|
|
187
|
+
## Output Quality
|
|
188
|
+
|
|
189
|
+
The tool produces high-quality analysis by:
|
|
190
|
+
- Using structured output to enforce consistency
|
|
191
|
+
- Extracting before summarizing for thorough coverage
|
|
192
|
+
- Maintaining citation integrity throughout the pipeline
|
|
193
|
+
- Validating all outputs against Pydantic schemas
|
|
194
|
+
- Applying domain-specific prompt engineering
|
|
195
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "unique-swot"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Unique Swot package is a tool that for conducting a swot analysis based on internal and external documents"
|
|
5
|
+
authors = ["Rami Azouz <rami.ext@unique.ch>", "Fabian Schläpfer <fabian.schlaepfer@unique.ai>"]
|
|
6
|
+
license = "Proprietary"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[tool.poetry.dependencies]
|
|
11
|
+
python = "^3.12"
|
|
12
|
+
pydantic = "^2.8.2"
|
|
13
|
+
ruff = "^0.11.7"
|
|
14
|
+
jinja2 = "^3.1.0"
|
|
15
|
+
python-docx = "^1.2.0"
|
|
16
|
+
beautifulsoup4 = "^4.14.2"
|
|
17
|
+
unique-toolkit = "^1.22.1"
|
|
18
|
+
|
|
19
|
+
[tool.poetry.group.dev.dependencies]
|
|
20
|
+
python = "^3.12"
|
|
21
|
+
pydantic = "^2.8.2"
|
|
22
|
+
pytest = "^8.3.5"
|
|
23
|
+
pytest-mock = "^3.14.0"
|
|
24
|
+
pytest-asyncio = "^1.2.0"
|
|
25
|
+
unique-toolkit = { path = "../../unique_toolkit", develop = true}
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
29
|
+
build-backend = "poetry.core.masonry.api"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
|
|
35
|
+
[tool.ruff.lint]
|
|
36
|
+
extend-select = ["I"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
from pydantic.json_schema import SkipJsonSchema
|
|
3
|
+
from unique_toolkit.agentic.tools.schemas import BaseToolConfig
|
|
4
|
+
|
|
5
|
+
from unique_swot.services.generation import ReportGenerationConfig
|
|
6
|
+
from unique_swot.services.report import ReportRendererConfig
|
|
7
|
+
|
|
8
|
+
TOOL_DESCRIPTION = """
|
|
9
|
+
This tool is used to perfom a SWOT analysis of a company by analyzing its strengths, weaknesses, opportunities, and threats.
|
|
10
|
+
The user can either generate a new SWOT analysis or modify an existing one.
|
|
11
|
+
If the user simply says RUN, the tool will generate a new SWOT analysis.
|
|
12
|
+
|
|
13
|
+
If the user simply says RUN, It means that he expects the tool to generate a new SWOT analysis.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SwotAnalysisToolConfig(BaseToolConfig):
|
|
18
|
+
cache_scope_id: str = Field(
|
|
19
|
+
default="",
|
|
20
|
+
description="The scope id for the SWOT analysis cache.",
|
|
21
|
+
)
|
|
22
|
+
report_generation_config: ReportGenerationConfig = Field(
|
|
23
|
+
default_factory=ReportGenerationConfig,
|
|
24
|
+
description="The configuration for the report generation.",
|
|
25
|
+
)
|
|
26
|
+
report_renderer_config: ReportRendererConfig = Field(
|
|
27
|
+
default_factory=ReportRendererConfig,
|
|
28
|
+
description="The configuration for the report renderer.",
|
|
29
|
+
)
|
|
30
|
+
tool_description: str = Field(
|
|
31
|
+
default=TOOL_DESCRIPTION,
|
|
32
|
+
description="The description of the SWOT analysis tool.",
|
|
33
|
+
)
|
|
34
|
+
tool_description_for_system_prompt: str = Field(
|
|
35
|
+
default=TOOL_DESCRIPTION,
|
|
36
|
+
description="The system prompt for the SWOT analysis tool.",
|
|
37
|
+
)
|
|
38
|
+
tool_format_information_for_system_prompt: SkipJsonSchema[str] = Field(
|
|
39
|
+
default="",
|
|
40
|
+
description="The format information for the SWOT analysis tool.",
|
|
41
|
+
)
|
|
42
|
+
tool_description_for_user_prompt: SkipJsonSchema[str] = Field(
|
|
43
|
+
default="",
|
|
44
|
+
description="The user prompt for the SWOT analysis tool.",
|
|
45
|
+
)
|
|
46
|
+
tool_format_information_for_user_prompt: SkipJsonSchema[str] = Field(
|
|
47
|
+
default="",
|
|
48
|
+
description="The format information for the SWOT analysis tool.",
|
|
49
|
+
)
|
|
50
|
+
tool_format_reminder_for_user_prompt: SkipJsonSchema[str] = Field(
|
|
51
|
+
default="",
|
|
52
|
+
description="The format reminder for the SWOT analysis tool.",
|
|
53
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
config:
|
|
3
|
+
layout: elk
|
|
4
|
+
---
|
|
5
|
+
flowchart TB
|
|
6
|
+
subgraph subGraph0["Generator Entry Point"]
|
|
7
|
+
A["Generation Request"]
|
|
8
|
+
B["Component Type"]
|
|
9
|
+
C["Sources"]
|
|
10
|
+
end
|
|
11
|
+
subgraph subGraph8["Request Types"]
|
|
12
|
+
D["Generation"]
|
|
13
|
+
E["Modification"]
|
|
14
|
+
end
|
|
15
|
+
subgraph subGraph1["Prompt Management System"]
|
|
16
|
+
F["Prompt Router"]
|
|
17
|
+
G["Strengths Prompt"]
|
|
18
|
+
H["Weaknesses Prompt"]
|
|
19
|
+
I["Opportunities Prompt"]
|
|
20
|
+
J["Threats Prompt"]
|
|
21
|
+
end
|
|
22
|
+
subgraph subGraph3["Processing Engine"]
|
|
23
|
+
N["Batch Processing"]
|
|
24
|
+
O["LLM Integration"]
|
|
25
|
+
P["Result Assembly"]
|
|
26
|
+
end
|
|
27
|
+
subgraph subGraph7["Prompt Features"]
|
|
28
|
+
CC["Component-Specific Instructions"]
|
|
29
|
+
DD["Output Format Guidelines"]
|
|
30
|
+
EE["Reference Requirements"]
|
|
31
|
+
FF["Analysis Depth Specifications"]
|
|
32
|
+
end
|
|
33
|
+
subgraph subGraph6["Prompt Templates"]
|
|
34
|
+
Y["Strengths Template"]
|
|
35
|
+
Z["Weaknesses Template"]
|
|
36
|
+
AA["Opportunities Template"]
|
|
37
|
+
BB["Threats Template"]
|
|
38
|
+
subGraph7
|
|
39
|
+
end
|
|
40
|
+
F --> G & H & I & J
|
|
41
|
+
Y --> CC
|
|
42
|
+
Z --> CC
|
|
43
|
+
AA --> CC
|
|
44
|
+
BB --> CC
|
|
45
|
+
CC --> DD
|
|
46
|
+
DD --> EE
|
|
47
|
+
EE --> FF
|
|
48
|
+
A --> subGraph8
|
|
49
|
+
B --> subGraph1
|
|
50
|
+
C --> subGraph3
|
|
51
|
+
subGraph8 --> subGraph1
|
|
52
|
+
subGraph1 --> subGraph6
|
|
53
|
+
subGraph3 --> subGraph1
|
|
54
|
+
A:::entry
|
|
55
|
+
B:::entry
|
|
56
|
+
C:::entry
|
|
57
|
+
D:::requestType
|
|
58
|
+
E:::requestType
|
|
59
|
+
F:::promptRouter
|
|
60
|
+
G:::strengthsPrompt
|
|
61
|
+
H:::weaknessesPrompt
|
|
62
|
+
I:::opportunitiesPrompt
|
|
63
|
+
J:::threatsPrompt
|
|
64
|
+
N:::processingEngine
|
|
65
|
+
O:::processingEngine
|
|
66
|
+
P:::processingEngine
|
|
67
|
+
CC:::promptFeature
|
|
68
|
+
DD:::promptFeature
|
|
69
|
+
EE:::promptFeature
|
|
70
|
+
FF:::promptFeature
|
|
71
|
+
Y:::promptTemplate
|
|
72
|
+
Z:::promptTemplate
|
|
73
|
+
AA:::promptTemplate
|
|
74
|
+
BB:::promptTemplate
|
|
75
|
+
classDef entry fill:#e3f2fd,stroke:#1976d2,stroke-width:3px
|
|
76
|
+
classDef requestType fill:#e8f5e8,stroke:#4caf50,stroke-width:2px
|
|
77
|
+
classDef promptRouter fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px
|
|
78
|
+
classDef strengthsPrompt fill:#e8f5e8,stroke:#4caf50,stroke-width:2px
|
|
79
|
+
classDef weaknessesPrompt fill:#fff3e0,stroke:#ff9800,stroke-width:2px
|
|
80
|
+
classDef opportunitiesPrompt fill:#e1f5fe,stroke:#2196f3,stroke-width:2px
|
|
81
|
+
classDef threatsPrompt fill:#ffebee,stroke:#f44336,stroke-width:2px
|
|
82
|
+
classDef modelRouter fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px
|
|
83
|
+
classDef strengthsModel fill:#e8f5e8,stroke:#4caf50,stroke-width:2px
|
|
84
|
+
classDef weaknessesModel fill:#fff3e0,stroke:#ff9800,stroke-width:2px
|
|
85
|
+
classDef opportunitiesModel fill:#e1f5fe,stroke:#2196f3,stroke-width:2px
|
|
86
|
+
classDef threatsModel fill:#ffebee,stroke:#f44336,stroke-width:2px
|
|
87
|
+
classDef processingEngine fill:#fff8e1,stroke:#f57c00,stroke-width:2px
|
|
88
|
+
classDef promptTemplate fill:#fce4ec,stroke:#c2185b,stroke-width:2px
|
|
89
|
+
classDef promptFeature fill:#f3e5f5,stroke:#7b1fa2,stroke-width:1px
|