File size: 2,751 Bytes
5a2d62e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from base_agent import BaseAgent
from models import AgentState
from typing import AsyncGenerator
import json

class SequenceDiagramGenerator(BaseAgent):
    async def __call__(self, state: AgentState) -> AsyncGenerator[str, None]:
        prompt_template = """
        Generate comprehensive PlantUML code for a sequence diagram based on:

        Workflow Analysis: {sequence_interactions}

        Instructions:
        1. Use proper participant types:
           - actor for human users
           - boundary for UI elements  
           - control for controllers
           - entity for domain objects
           - database for storage
        2. Include all message types:
           - Synchronous: ->
           - Asynchronous: ->>
           - Return: -->
           - Self: -> self
        3. Add activation bars with:
           - activate/deactivate
           - Nested activations where needed
        4. Use advanced features:
           - Groups (alt/opt/loop/par)
           - Notes
           - Dividers (== Sections ==)
           - Stereotypes <<component>>
           - Arrows with:
             * Lost messages (->x)
             * Found messages (x->)
             * Parallel (->||)
        5. Format for readability:
           - Proper indentation
           - Section comments
           - Color coding where helpful

        Example Structure (DO NOT TREAT AS VARIABLES):
        @startuml
        skinparam style strictuml
        skinparam lifelineStrategy solid
        
        actor Customer <<Human>>
        boundary "Web UI" as UI
        control OrderController
        entity Order
        database OrderDB
        
        == Order Submission ==
        Customer -> UI: Submit Order
        activate UI
        UI -> OrderController: processOrder()
        activate OrderController
        
        group Payment Processing
            OrderController -> PaymentService <<External>>: authorizePayment()
            activate PaymentService
            PaymentService --> OrderController: status
            deactivate PaymentService
        end
        
        alt payment approved
            OrderController -> OrderDB: persistOrder()
            OrderController --> UI: confirmation
        else payment declined
            OrderController --> UI: error
        end
        
        deactivate OrderController
        UI --> Customer: Order Status
        deactivate UI
        @enduml
        """

        async for chunk in self._stream_process(
            state=state,
            prompt_template=prompt_template,
            output_key="sequence_diagram",
            step_name="generate_sequence_diagram",
            sequence_interactions=state["sequence_interactions"]
        ):
            yield chunk