process-gpt-agent-sdk 0.3.11__py3-none-any.whl → 0.3.13__py3-none-any.whl

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.

Potentially problematic release.


This version of process-gpt-agent-sdk might be problematic. Click here for more details.

@@ -0,0 +1,690 @@
1
+ Metadata-Version: 2.4
2
+ Name: process-gpt-agent-sdk
3
+ Version: 0.3.13
4
+ Summary: Supabase 기반 이벤트/작업 폴링으로 A2A AgentExecutor를 실행하는 SDK
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/your-org/process-gpt-agent-sdk
7
+ Project-URL: Issues, https://github.com/your-org/process-gpt-agent-sdk/issues
8
+ Keywords: agent,a2a,supabase,workflow,sdk,processgpt
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: supabase>=2.0.0
16
+ Requires-Dist: python-dotenv>=1.0.0
17
+ Requires-Dist: click>=8.0.0
18
+ Requires-Dist: asyncio-mqtt>=0.13.0
19
+ Requires-Dist: jsonschema>=4.0.0
20
+ Requires-Dist: structlog>=23.0.0
21
+ Requires-Dist: typing-extensions>=4.0.0
22
+ Requires-Dist: python-dateutil>=2.8.0
23
+ Requires-Dist: a2a-sdk==0.3.0
24
+
25
+ # ProcessGPT Agent Framework
26
+ ## A2A SDK 연동을 위한 경량 에이전트 서버 프레임워크
27
+
28
+ Supabase 기반의 프로세스 작업(Todolist)을 폴링하고, A2A 규격 이벤트를 통해 작업 상태/결과를 기록하는 **경량 에이전트 서버 프레임워크**입니다.
29
+
30
+ ### 📋 요구사항
31
+ - **런타임**: Python 3.9+ (권장: Python 3.11)
32
+ - **데이터베이스**: Supabase (PostgreSQL) + 제공된 RPC/테이블
33
+ - **이벤트 규격**: A2A `TaskStatusUpdateEvent` / `TaskArtifactUpdateEvent`
34
+
35
+ ## 📊 이벤트 종류 및 데이터 구조
36
+
37
+ ### 🎯 이벤트 타입 (event_type) 종류
38
+
39
+ | event_type | 설명 | 사용 시점 | 자동 설정 여부 |
40
+ |------------|------|-----------|----------------|
41
+ | `task_started` | 작업 시작 | 작업 처리 시작시 | 수동 설정 |
42
+ | `task_completed` | 작업 완료 | 작업 정상 완료시 | 수동 설정 |
43
+ | `crew_completed` | 크루 작업 완료 | 서버가 작업 종료시 | **자동 설정** |
44
+ | `tool_usage_started` | 도구 사용 시작 | 외부 도구/API 호출 시작 | 수동 설정 |
45
+ | `tool_usage_finished` | 도구 사용 완료 | 외부 도구/API 호출 완료 | 수동 설정 |
46
+ | `human_asked` | 사용자 입력 요청 | HITL 패턴 사용시 | **자동 설정** |
47
+ | `human_response` | 사용자 응답 | UI에서 사용자 응답시 | UI가 설정 |
48
+
49
+ ### 📋 메타데이터 필드 설명
50
+
51
+ #### crew_type (필수)
52
+ - **의미**: 현재 조직의 크루 이름 또는 행위를 나타냄
53
+ - **예시**: `action`, `report`, `slide`, `analysis`, `research` 등
54
+ - **사용법**: 어떤 종류의 작업인지 분류하는 데 사용
55
+
56
+ ```python
57
+ metadata = {
58
+ "crew_type": "action", # 액션 수행 크루
59
+ "event_type": "task_started"
60
+ }
61
+ ```
62
+
63
+ #### job_id (중요)
64
+ - **의미**: 하나의 작업 단위를 식별하는 고유 ID
65
+ - **규칙**: **시작과 끝이 반드시 매칭되어야 함**
66
+ - **형식**: `job-{task_id}` 또는 `job-{timestamp}` 등
67
+
68
+ ```python
69
+ # 올바른 사용법 - 동일한 job_id 사용
70
+ job_id = f"job-{task_id}"
71
+
72
+ # 작업 시작
73
+ metadata = {"crew_type": "action", "event_type": "task_started", "job_id": job_id}
74
+
75
+ # HITL 요청
76
+ metadata = {"crew_type": "action", "job_id": job_id} # human_asked 자동 설정
77
+
78
+ # 작업 완료
79
+ metadata = {"crew_type": "action", "event_type": "task_completed", "job_id": job_id}
80
+ ```
81
+
82
+ ### 🔄 이벤트 저장 방식
83
+
84
+ #### 1. TaskStatusUpdateEvent → `events` 테이블
85
+ ```python
86
+ event_queue.enqueue_event(
87
+ TaskStatusUpdateEvent(
88
+ status={
89
+ "state": TaskState.working,
90
+ "message": new_agent_text_message("진행 상황 메시지", context_id, task_id),
91
+ },
92
+ final=False,
93
+ contextId=context_id,
94
+ taskId=task_id,
95
+ metadata={
96
+ "crew_type": "action",
97
+ "event_type": "task_started", # events.event_type에 저장
98
+ "job_id": "job-12345"
99
+ }
100
+ )
101
+ )
102
+ ```
103
+
104
+ **저장 결과** (events 테이블):
105
+ - `event_type`: "task_started"
106
+ - `data`: "진행 상황 메시지" (래퍼 제거된 순수 텍스트)
107
+ - `metadata`: 전체 metadata JSON
108
+
109
+ #### 2. TaskArtifactUpdateEvent → `todolist.output` 컬럼
110
+ ```python
111
+ artifact = new_text_artifact(
112
+ name="처리결과",
113
+ description="작업 완료 결과",
114
+ text=json.dumps({"result": "완료"}, ensure_ascii=False)
115
+ )
116
+ event_queue.enqueue_event(
117
+ TaskArtifactUpdateEvent(
118
+ artifact=artifact,
119
+ lastChunk=True, # 최종 결과
120
+ contextId=context_id,
121
+ taskId=task_id,
122
+ )
123
+ )
124
+ ```
125
+
126
+ **저장 결과** (todolist 테이블):
127
+ - `output`: `{"result": "완료"}` (래퍼 제거된 순수 JSON)
128
+ - `p_final`: `true`
129
+
130
+ ### ⚠️ 특별 규칙
131
+
132
+ 1. **자동 event_type 설정**:
133
+ - `state=input_required` → `event_type=human_asked` (자동)
134
+ - 작업 완료시 → `event_type=crew_completed` (서버가 자동 추가)
135
+
136
+ 2. **JSON 문자열 변환 필수**:
137
+ ```python
138
+ # 올바른 방법
139
+ text=json.dumps(data, ensure_ascii=False)
140
+
141
+ # 잘못된 방법
142
+ text=data # 딕셔너리 직접 전달 시 래퍼와 함께 저장됨
143
+ ```
144
+
145
+ ## 🔄 전체 데이터 흐름도
146
+
147
+ ```mermaid
148
+ graph TD
149
+ A[Supabase todolist 테이블] -->|폴링| B[ProcessGPTAgentServer]
150
+ B -->|작업 발견| C[RequestContext 생성]
151
+ C -->|컨텍스트 전달| D[AgentExecutor.execute]
152
+
153
+ D -->|진행 상태| E[TaskStatusUpdateEvent]
154
+ D -->|최종 결과| F[TaskArtifactUpdateEvent]
155
+ D -->|HITL 요청| G[TaskStatusUpdateEvent<br/>state=input_required]
156
+
157
+ E -->|래퍼 제거| H[events 테이블<br/>data 컬럼]
158
+ F -->|래퍼 제거| I[todolist.output 컬럼<br/>p_final=true]
159
+ G -->|자동 설정| J[events 테이블<br/>event_type=human_asked]
160
+
161
+ K[Operator UI] -->|사용자 응답| L[events 테이블<br/>event_type=human_response]
162
+
163
+ style E fill:#e1f5fe
164
+ style F fill:#f3e5f5
165
+ style G fill:#fff3e0
166
+ ```
167
+
168
+ ### 🎯 job_id 생명주기 흐름
169
+
170
+ ```mermaid
171
+ sequenceDiagram
172
+ participant S as Server
173
+ participant E as Executor
174
+ participant DB as Supabase
175
+ participant UI as Operator UI
176
+
177
+ Note over E: job_id = "job-12345" 생성
178
+
179
+ E->>DB: TaskStatusUpdateEvent<br/>event_type=task_started<br/>job_id=job-12345
180
+
181
+ E->>DB: TaskStatusUpdateEvent<br/>event_type=tool_usage_started<br/>job_id=job-12345
182
+
183
+ E->>DB: TaskStatusUpdateEvent<br/>event_type=tool_usage_finished<br/>job_id=job-12345
184
+
185
+ alt HITL 필요시
186
+ E->>DB: TaskStatusUpdateEvent<br/>state=input_required<br/>job_id=job-12345
187
+ Note over DB: 자동으로 event_type=human_asked 설정
188
+
189
+ UI->>DB: INSERT events<br/>event_type=human_response<br/>job_id=job-12345
190
+ end
191
+
192
+ E->>DB: TaskArtifactUpdateEvent<br/>lastChunk=true
193
+
194
+ E->>DB: TaskStatusUpdateEvent<br/>event_type=task_completed<br/>job_id=job-12345
195
+
196
+ S->>DB: TaskStatusUpdateEvent<br/>event_type=crew_completed<br/>job_id=job-12345
197
+
198
+ Note over S,UI: 동일한 job_id로 시작부터 끝까지 추적 가능
199
+ ```
200
+
201
+ ### 💾 데이터 저장 구조
202
+
203
+ #### events 테이블 저장 예시
204
+ ```json
205
+ {
206
+ "id": "uuid",
207
+ "event_type": "task_started",
208
+ "data": "작업을 시작합니다", // 래퍼 제거된 순수 메시지
209
+ "metadata": {
210
+ "crew_type": "action",
211
+ "event_type": "task_started",
212
+ "job_id": "job-12345",
213
+ "contextId": "proc-789",
214
+ "taskId": "task-456"
215
+ },
216
+ "created_at": "2024-01-01T00:00:00Z"
217
+ }
218
+ ```
219
+
220
+ #### todolist.output 저장 예시
221
+ ```json
222
+ {
223
+ "id": "task-456",
224
+ "output": {
225
+ "status": "completed",
226
+ "result": "처리 결과 데이터"
227
+ }, // 래퍼 제거된 순수 아티팩트 데이터
228
+ "p_final": true,
229
+ "updated_at": "2024-01-01T00:05:00Z"
230
+ }
231
+ ```
232
+
233
+ ### 🔧 값 전달 과정
234
+ ```python
235
+ # 1. 서버에서 작업 정보 가져오기
236
+ row = context.get_context_data()["row"] # todolist 테이블의 한 행
237
+ context_id = row.get("root_proc_inst_id") or row.get("proc_inst_id") # 프로세스 ID
238
+ task_id = row.get("id") # 작업 ID
239
+ user_input = context.get_user_input() # 사용자가 입력한 내용
240
+
241
+ # 2. job_id 생성 (작업 전체 추적용)
242
+ job_id = f"job-{task_id}" # 또는 timestamp 기반
243
+
244
+ # 3. 메시지/아티팩트 생성시 JSON 문자열로 변환
245
+ payload = {"result": "처리 완료"}
246
+ message_text = json.dumps(payload, ensure_ascii=False) # 중요: JSON 문자열로!
247
+
248
+ # 4. 메타데이터에 crew_type, job_id 포함
249
+ metadata = {
250
+ "crew_type": "action", # 크루 타입
251
+ "event_type": "task_started", # 이벤트 타입
252
+ "job_id": job_id # 작업 추적 ID
253
+ }
254
+
255
+ # 5. 서버가 자동으로 래퍼 제거 후 순수 payload만 저장
256
+ # events.data 또는 todolist.output에 {"result": "처리 완료"}만 저장됨
257
+ ```
258
+
259
+ ## 🚀 빠른 시작 가이드
260
+
261
+ ### 1단계: 설치
262
+ ```bash
263
+ # 패키지 설치
264
+ pip install -e .
265
+
266
+ # 또는 requirements.txt 사용
267
+ pip install -r requirements.txt
268
+ ```
269
+
270
+ ### 2단계: 환경 설정
271
+ `.env` 파일 생성:
272
+ ```env
273
+ SUPABASE_URL=your_supabase_project_url
274
+ SUPABASE_KEY=your_supabase_anon_key
275
+ ENV=dev
276
+ ```
277
+
278
+ ### 3단계: 서버 구현 방법
279
+ 서버는 이렇게 만드세요:
280
+
281
+ ```python
282
+ # my_server.py
283
+ import asyncio
284
+ from dotenv import load_dotenv
285
+ from processgpt_agent_sdk.processgpt_agent_framework import ProcessGPTAgentServer
286
+ from my_executor import MyExecutor # 아래에서 구현할 익스큐터
287
+
288
+ async def main():
289
+ load_dotenv()
290
+
291
+ server = ProcessGPTAgentServer(
292
+ agent_executor=MyExecutor(), # 여러분이 구현할 익스큐터
293
+ agent_type="my-agent" # Supabase todolist.agent_orch와 매칭되어야 함
294
+ )
295
+ server.polling_interval = 3 # 3초마다 새 작업 확인
296
+
297
+ print("서버 시작!")
298
+ await server.run()
299
+
300
+ if __name__ == "__main__":
301
+ try:
302
+ asyncio.run(main())
303
+ except KeyboardInterrupt:
304
+ print("서버 종료")
305
+ ```
306
+
307
+ ### 4단계: 익스큐터 구현 방법
308
+ 익스큐터는 이렇게 만드세요:
309
+
310
+ ```python
311
+ # my_executor.py
312
+ import asyncio
313
+ import json
314
+ from typing_extensions import override
315
+ from a2a.server.agent_execution import AgentExecutor, RequestContext
316
+ from a2a.server.events import EventQueue
317
+ from a2a.types import TaskStatusUpdateEvent, TaskState, TaskArtifactUpdateEvent
318
+ from a2a.utils import new_agent_text_message, new_text_artifact
319
+
320
+ class MyExecutor(AgentExecutor):
321
+ @override
322
+ async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
323
+ # 1. 작업 정보 가져오기
324
+ row = context.get_context_data()["row"]
325
+ context_id = row.get("root_proc_inst_id") or row.get("proc_inst_id")
326
+ task_id = row.get("id")
327
+ user_input = context.get_user_input() # 사용자가 입력한 내용
328
+
329
+ # 2. job_id 생성 (작업 전체 추적용)
330
+ job_id = f"job-{task_id}"
331
+
332
+ print(f"처리할 작업: {user_input} (job_id: {job_id})")
333
+
334
+ # 3. 작업 시작 알림 (events 테이블에 저장됨)
335
+ event_queue.enqueue_event(
336
+ TaskStatusUpdateEvent(
337
+ status={
338
+ "state": TaskState.working,
339
+ "message": new_agent_text_message("작업 시작", context_id, task_id),
340
+ },
341
+ final=False,
342
+ contextId=context_id,
343
+ taskId=task_id,
344
+ metadata={
345
+ "crew_type": "action", # 크루 타입
346
+ "event_type": "task_started",
347
+ "job_id": job_id # 작업 추적 ID
348
+ }
349
+ )
350
+ )
351
+
352
+ # 4. 실제 작업 수행 (여기에 여러분의 로직 작성)
353
+ await asyncio.sleep(2)
354
+ result_data = {"status": "완료", "input": user_input, "output": "처리 결과"}
355
+
356
+ # 5. 작업 완료 알림
357
+ event_queue.enqueue_event(
358
+ TaskStatusUpdateEvent(
359
+ status={
360
+ "state": TaskState.working,
361
+ "message": new_agent_text_message("작업 완료", context_id, task_id),
362
+ },
363
+ final=False,
364
+ contextId=context_id,
365
+ taskId=task_id,
366
+ metadata={
367
+ "crew_type": "action",
368
+ "event_type": "task_completed",
369
+ "job_id": job_id # 동일한 job_id 사용
370
+ }
371
+ )
372
+ )
373
+
374
+ # 6. 최종 결과 전송 (todolist.output에 저장됨)
375
+ artifact = new_text_artifact(
376
+ name="처리결과",
377
+ description="작업 완료 결과",
378
+ text=json.dumps(result_data, ensure_ascii=False) # JSON 문자열로!
379
+ )
380
+ event_queue.enqueue_event(
381
+ TaskArtifactUpdateEvent(
382
+ artifact=artifact,
383
+ lastChunk=True, # 중요: 최종 결과면 True
384
+ contextId=context_id,
385
+ taskId=task_id,
386
+ )
387
+ )
388
+
389
+ @override
390
+ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
391
+ pass # 취소 로직 (필요시 구현)
392
+ ```
393
+
394
+ ### 5단계: 실행
395
+ ```bash
396
+ python my_server.py
397
+ ```
398
+
399
+ ## 🤝 Human-in-the-Loop (사용자 입력 요청) 패턴
400
+
401
+ 사용자 입력이 필요한 완전한 예시:
402
+
403
+ ```python
404
+ class HITLExecutor(AgentExecutor):
405
+ @override
406
+ async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
407
+ row = context.get_context_data()["row"]
408
+ context_id = row.get("root_proc_inst_id") or row.get("proc_inst_id")
409
+ task_id = row.get("id")
410
+ user_input = context.get_user_input()
411
+ job_id = f"job-{task_id}"
412
+
413
+ # 1. 작업 시작
414
+ event_queue.enqueue_event(
415
+ TaskStatusUpdateEvent(
416
+ status={
417
+ "state": TaskState.working,
418
+ "message": new_agent_text_message("분석을 시작합니다", context_id, task_id),
419
+ },
420
+ final=False,
421
+ contextId=context_id,
422
+ taskId=task_id,
423
+ metadata={
424
+ "crew_type": "analysis", # 분석 크루
425
+ "event_type": "task_started",
426
+ "job_id": job_id
427
+ }
428
+ )
429
+ )
430
+
431
+ await asyncio.sleep(1)
432
+
433
+ # 2. 사용자 입력 요청 (HITL)
434
+ question_data = {
435
+ "question": f"'{user_input}' 작업을 어떤 방식으로 처리할까요?",
436
+ "options": ["빠른 처리", "정밀 분석", "단계별 진행"],
437
+ "context": user_input
438
+ }
439
+
440
+ event_queue.enqueue_event(
441
+ TaskStatusUpdateEvent(
442
+ status={
443
+ "state": TaskState.input_required, # 중요: 자동으로 human_asked 설정됨
444
+ "message": new_agent_text_message(
445
+ json.dumps(question_data, ensure_ascii=False),
446
+ context_id, task_id
447
+ ),
448
+ },
449
+ final=True,
450
+ contextId=context_id,
451
+ taskId=task_id,
452
+ metadata={
453
+ "crew_type": "analysis",
454
+ "job_id": job_id # 동일한 job_id 유지
455
+ }
456
+ )
457
+ )
458
+
459
+ # 3. 사용자 응답을 기다리는 로직 (실제 구현에서는 필요)
460
+ # 여기서는 시뮬레이션
461
+ await asyncio.sleep(3)
462
+
463
+ # 4. 사용자 응답 후 작업 완료
464
+ result_data = {
465
+ "original_request": user_input,
466
+ "user_choice": "사용자가 선택한 옵션",
467
+ "result": "HITL 방식으로 처리 완료"
468
+ }
469
+
470
+ # 5. 완료 알림
471
+ event_queue.enqueue_event(
472
+ TaskStatusUpdateEvent(
473
+ status={
474
+ "state": TaskState.working,
475
+ "message": new_agent_text_message("HITL 처리 완료", context_id, task_id),
476
+ },
477
+ final=False,
478
+ contextId=context_id,
479
+ taskId=task_id,
480
+ metadata={
481
+ "crew_type": "analysis",
482
+ "event_type": "task_completed",
483
+ "job_id": job_id # 동일한 job_id로 완료
484
+ }
485
+ )
486
+ )
487
+
488
+ # 6. 최종 결과
489
+ artifact = new_text_artifact(
490
+ name="HITL_결과",
491
+ description="Human-in-the-Loop 처리 결과",
492
+ text=json.dumps(result_data, ensure_ascii=False)
493
+ )
494
+ event_queue.enqueue_event(
495
+ TaskArtifactUpdateEvent(
496
+ artifact=artifact,
497
+ lastChunk=True,
498
+ contextId=context_id,
499
+ taskId=task_id,
500
+ )
501
+ )
502
+
503
+ @override
504
+ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
505
+ pass
506
+ ```
507
+
508
+ ## 📋 체크리스트 (실패 없는 통합을 위한)
509
+
510
+ ### 필수 설정
511
+ - [ ] `.env`에 `SUPABASE_URL`, `SUPABASE_KEY` 설정
512
+ - [ ] `requirements.txt` 설치 완료
513
+ - [ ] Supabase에서 제공 SQL(`database_schema.sql`, `function.sql`) 적용
514
+
515
+ ### 코드 구현
516
+ - [ ] 서버에서 `agent_type`이 Supabase `todolist.agent_orch`와 매칭됨
517
+ - [ ] 익스큐터에서 `contextId`, `taskId`를 올바르게 설정
518
+ - [ ] **job_id 생성 및 일관성 유지** (`job-{task_id}` 형식 권장)
519
+ - [ ] **crew_type 설정** (`action`, `report`, `slide` 등 행위별 분류)
520
+ - [ ] 상태 이벤트는 `new_agent_text_message()`로 생성
521
+ - [ ] 최종 결과는 `new_text_artifact()` + `lastChunk=True`로 전송
522
+ - [ ] HITL 요청시 `TaskState.input_required` 사용
523
+ - [ ] **JSON 문자열 변환** (`json.dumps(data, ensure_ascii=False)`)
524
+
525
+ ## 🚨 자주 발생하는 문제
526
+
527
+ ### 1. 설치 문제
528
+ **증상**: `ModuleNotFoundError`
529
+ ```bash
530
+ # 해결
531
+ pip install -e .
532
+ pip install a2a-sdk==0.3.0 --force-reinstall
533
+ ```
534
+
535
+ ### 2. 작업이 폴링되지 않음
536
+ **원인**: Supabase 연결 문제
537
+ **해결**:
538
+ - `.env` 파일 위치 확인 (프로젝트 루트)
539
+ - URL/Key 재확인
540
+ - `agent_type`이 todolist.agent_orch와 매칭되는지 확인
541
+
542
+ ### 3. 이벤트가 저장되지 않음
543
+ **원인**: 테이블/함수 누락
544
+ **해결**:
545
+ - `database_schema.sql`, `function.sql` 실행 확인
546
+ - Supabase 테이블 권한 확인
547
+
548
+ ### 4. 결과가 래퍼와 함께 저장됨
549
+ **원인**: JSON 문자열 변환 누락
550
+ ```python
551
+ # 올바른 방법
552
+ text=json.dumps(data, ensure_ascii=False) # JSON 문자열로!
553
+
554
+ # 잘못된 방법
555
+ text=data # 딕셔너리 직접 전달 (X)
556
+ ```
557
+
558
+ ## 📚 샘플 코드 (간단 버전)
559
+
560
+ ### 기본 서버
561
+ ```python
562
+ # sample_server/minimal_server.py
563
+ import asyncio
564
+ from dotenv import load_dotenv
565
+ from processgpt_agent_sdk.processgpt_agent_framework import ProcessGPTAgentServer
566
+ from sample_server.minimal_executor import MinimalExecutor
567
+
568
+ async def main():
569
+ load_dotenv()
570
+ server = ProcessGPTAgentServer(
571
+ agent_executor=MinimalExecutor(),
572
+ agent_type="crewai-action"
573
+ )
574
+ server.polling_interval = 3
575
+ await server.run()
576
+
577
+ if __name__ == "__main__":
578
+ try:
579
+ asyncio.run(main())
580
+ except KeyboardInterrupt:
581
+ pass
582
+ ```
583
+
584
+ ### 기본 익스큐터
585
+ ```python
586
+ # sample_server/minimal_executor.py
587
+ import asyncio
588
+ import json
589
+ from typing_extensions import override
590
+ from a2a.server.agent_execution import AgentExecutor, RequestContext
591
+ from a2a.server.events import EventQueue
592
+ from a2a.types import TaskStatusUpdateEvent, TaskState, TaskArtifactUpdateEvent
593
+ from a2a.utils import new_agent_text_message, new_text_artifact
594
+
595
+ class MinimalExecutor(AgentExecutor):
596
+ @override
597
+ async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
598
+ row = context.get_context_data()["row"]
599
+ context_id = row.get("root_proc_inst_id") or row.get("proc_inst_id")
600
+ task_id = row.get("id")
601
+ user_input = context.get_user_input()
602
+
603
+ # 진행 상태
604
+ event_queue.enqueue_event(
605
+ TaskStatusUpdateEvent(
606
+ status={
607
+ "state": TaskState.working,
608
+ "message": new_agent_text_message("처리중", context_id, task_id),
609
+ },
610
+ final=False,
611
+ contextId=context_id,
612
+ taskId=task_id,
613
+ metadata={"event_type": "task_started"}
614
+ )
615
+ )
616
+
617
+ await asyncio.sleep(1)
618
+
619
+ # 최종 결과
620
+ result = {"input": user_input, "output": "처리 완료"}
621
+ artifact = new_text_artifact(
622
+ name="결과",
623
+ description="처리 결과",
624
+ text=json.dumps(result, ensure_ascii=False)
625
+ )
626
+ event_queue.enqueue_event(
627
+ TaskArtifactUpdateEvent(
628
+ artifact=artifact,
629
+ lastChunk=True,
630
+ contextId=context_id,
631
+ taskId=task_id,
632
+ )
633
+ )
634
+
635
+ @override
636
+ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
637
+ pass
638
+ ```
639
+
640
+ ## 🔧 실행 방법
641
+
642
+ ### 개발 환경에서 실행
643
+ ```bash
644
+ python sample_server/minimal_server.py
645
+ ```
646
+
647
+ ### 실제 사용시
648
+ ```bash
649
+ python my_server.py
650
+ ```
651
+
652
+ ## 🚀 배포/버전업 (PyPI/TestPyPI)
653
+
654
+ - 사전 준비: PyPI 혹은 TestPyPI 토큰 환경변수 설정
655
+
656
+ macOS/Linux:
657
+ ```bash
658
+ # TestPyPI 배포 예시
659
+ export TEST_PYPI_TOKEN="<your_testpypi_token>"
660
+ ./release.sh 0.3.13 testpypi
661
+
662
+ # PyPI 배포 예시
663
+ export PYPI_TOKEN="<your_pypi_token>"
664
+ ./release.sh 0.3.13 pypi
665
+ ```
666
+
667
+ Windows PowerShell:
668
+ ```powershell
669
+ # TestPyPI 배포 예시
670
+ $env:TEST_PYPI_TOKEN="<your_testpypi_token>"
671
+ ./release.ps1 -Version 0.3.13 -TestPyPI
672
+
673
+ # PyPI 배포 예시
674
+ $env:PYPI_TOKEN="<your_pypi_token>"
675
+ ./release.ps1 -Version 0.3.13
676
+ ```
677
+
678
+ ---
679
+
680
+ ## 📚 레퍼런스
681
+
682
+ ### 주요 함수들
683
+ - `ProcessGPTAgentServer.run()`: 서버 시작
684
+ - `new_agent_text_message(text, context_id, task_id)`: 상태 메시지 생성
685
+ - `new_text_artifact(name, desc, text)`: 결과 아티팩트 생성
686
+
687
+ ### 이벤트 저장 규칙
688
+ - **TaskStatusUpdateEvent** → `events` 테이블 (`data` 컬럼)
689
+ - **TaskArtifactUpdateEvent** → `todolist` 테이블 (`output` 컬럼)
690
+ - 래퍼 자동 제거 후 순수 payload만 저장
@@ -0,0 +1,7 @@
1
+ processgpt_agent_sdk/__init__.py,sha256=-Kwyodop7dRL1qy3UjW06X0vJoDqd2-cVlbesplIUmc,1108
2
+ processgpt_agent_sdk/database.py,sha256=G9nln9QTSfgPf3FfzLKwbXf3esEPz07rWVmzttxKTWE,18989
3
+ processgpt_agent_sdk/processgpt_agent_framework.py,sha256=QnYPV065da3bRL_xOYxaMOqQQUVv6D8CZ9d6cVL0-i4,16909
4
+ process_gpt_agent_sdk-0.3.13.dist-info/METADATA,sha256=NzdFo_djoSoyuEQJFr_-0SD3Cm_scQ72ZgpBt_4_hXw,22736
5
+ process_gpt_agent_sdk-0.3.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ process_gpt_agent_sdk-0.3.13.dist-info/top_level.txt,sha256=Xe6zrj3_3Vv7d0pl5RRtenVUckwOVBVLQn2P03j5REo,21
7
+ process_gpt_agent_sdk-0.3.13.dist-info/RECORD,,
@@ -0,0 +1,48 @@
1
+ """
2
+ ProcessGPT Agent SDK
3
+
4
+ 이 패키지는 ProcessGPT 시스템과 통합하기 위한 Agent Framework를 제공합니다.
5
+ """
6
+
7
+ from .processgpt_agent_framework import (
8
+ ProcessGPTAgentServer,
9
+ ProcessGPTRequestContext,
10
+ ProcessGPTEventQueue,
11
+ TodoListRowContext,
12
+ )
13
+
14
+ from .database import (
15
+ initialize_db,
16
+ polling_pending_todos,
17
+ record_event,
18
+ save_task_result,
19
+ update_task_error,
20
+ get_consumer_id,
21
+ fetch_agent_data,
22
+ fetch_all_agents,
23
+ fetch_form_types,
24
+ fetch_tenant_mcp_config,
25
+ fetch_human_users_by_proc_inst_id,
26
+ )
27
+
28
+ __version__ = "0.3.12"
29
+
30
+ __all__ = [
31
+ # Framework classes
32
+ "ProcessGPTAgentServer",
33
+ "ProcessGPTRequestContext",
34
+ "ProcessGPTEventQueue",
35
+ "TodoListRowContext",
36
+ # Database functions
37
+ "initialize_db",
38
+ "polling_pending_todos",
39
+ "record_event",
40
+ "save_task_result",
41
+ "update_task_error",
42
+ "get_consumer_id",
43
+ "fetch_agent_data",
44
+ "fetch_all_agents",
45
+ "fetch_form_types",
46
+ "fetch_tenant_mcp_config",
47
+ "fetch_human_users_by_proc_inst_id",
48
+ ]
@@ -210,7 +210,7 @@ async def fetch_all_agents() -> List[Dict[str, Any]]:
210
210
  client = get_db_client()
211
211
  return (
212
212
  client.table("users")
213
- .select("id, username, role, goal, persona, tools, profile, model, tenant_id, is_agent")
213
+ .select("id, username, role, goal, persona, tools, profile, model, tenant_id, is_agent, endpoint")
214
214
  .eq("is_agent", True)
215
215
  .execute()
216
216
  )
@@ -17,7 +17,7 @@ from a2a.types import (
17
17
  )
18
18
 
19
19
  # DB 어댑터 사용
20
- from database import (
20
+ from .database import (
21
21
  initialize_db,
22
22
  polling_pending_todos,
23
23
  record_event,
@@ -388,7 +388,7 @@ class ProcessGPTAgentServer:
388
388
  async def mark_task_failed(self, todolist_id: str, error_message: str):
389
389
  """태스크 실패 처리 (DB 상태 업데이트)"""
390
390
  try:
391
- await update_task_error(todolist_id)
391
+ await update_task_error(todolist_id, error_message)
392
392
  except Exception as e:
393
393
  logger.exception(
394
394
  "mark_task_failed error (todolist_id=%s): %s",
@@ -1,336 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: process-gpt-agent-sdk
3
- Version: 0.3.11
4
- Summary: Supabase 기반 이벤트/작업 폴링으로 A2A AgentExecutor를 실행하는 SDK
5
- License: MIT
6
- Project-URL: Homepage, https://github.com/your-org/process-gpt-agent-sdk
7
- Project-URL: Issues, https://github.com/your-org/process-gpt-agent-sdk/issues
8
- Keywords: agent,a2a,supabase,workflow,sdk,processgpt
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3 :: Only
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Requires-Python: >=3.9
14
- Description-Content-Type: text/markdown
15
- Requires-Dist: supabase>=2.0.0
16
- Requires-Dist: python-dotenv>=1.0.0
17
- Requires-Dist: click>=8.0.0
18
- Requires-Dist: asyncio-mqtt>=0.13.0
19
- Requires-Dist: jsonschema>=4.0.0
20
- Requires-Dist: structlog>=23.0.0
21
- Requires-Dist: typing-extensions>=4.0.0
22
- Requires-Dist: python-dateutil>=2.8.0
23
- Requires-Dist: a2a-sdk==0.3.0
24
-
25
- # ProcessGPT Agent Framework (A2A SDK 연동 가이드)
26
-
27
- 이 저장소는 Supabase 기반의 프로세스 작업(Todolist)을 폴링하고, A2A 규격 이벤트를 통해 작업 상태/결과를 기록하는 **경량 에이전트 서버 프레임워크**입니다. 최소 구현으로 빠르게 통합하고, 필요하면 커스터마이즈할 수 있습니다.
28
-
29
- - 런타임: Python 3.10+
30
- - 저장소 의존: Supabase(Postgres) + 제공된 RPC/테이블
31
- - 이벤트 규격: A2A `TaskStatusUpdateEvent` / `TaskArtifactUpdateEvent`
32
-
33
-
34
- ## 아키텍처 한눈에 보기
35
- ```mermaid
36
- flowchart LR
37
- subgraph Supabase
38
- A[Todolist] --- B[Events]
39
- A -.RPC.-> C[(save_task_result)]
40
- D[(fetch_pending_task)] --> A
41
- end
42
-
43
- subgraph Agent Server
44
- E[ProcessGPTAgentServer] -->|polls| D
45
- E --> F[ProcessGPTRequestContext]
46
- E --> G[ProcessGPTEventQueue]
47
- H[Your AgentExecutor]
48
- F --> H
49
- H -->|A2A Events| G
50
- end
51
-
52
- G -->|TaskStatusUpdateEvent| B
53
- G -->|TaskArtifactUpdateEvent| A
54
- ```
55
-
56
- - 서버는 주기적으로 Todolist를 폴링하여 새 작업을 가져옵니다.
57
- - 사용자 구현 `AgentExecutor`가 요청을 처리하고, A2A 이벤트를 큐에 전달합니다.
58
- - 이벤트 큐는 상태 이벤트를 `events` 테이블에, 아티팩트 이벤트를 `todolist.output`에 저장합니다.
59
-
60
-
61
- ## 엔드-투-엔드 시퀀스(정상 흐름)
62
- ```mermaid
63
- sequenceDiagram
64
- participant SB as Supabase
65
- participant SRV as ProcessGPTAgentServer
66
- participant CTX as RequestContext
67
- participant EXE as Your AgentExecutor
68
- participant EQ as ProcessGPTEventQueue
69
-
70
- SRV->>SB: RPC fetch_pending_task
71
- SB-->>SRV: todolist row
72
- SRV->>CTX: prepare_context()
73
- SRV->>EXE: execute(context, event_queue)
74
- EXE->>EQ: TaskStatusUpdateEvent (state=working)
75
- EQ->>SB: INSERT events (data=payload)
76
- EXE->>EQ: TaskArtifactUpdateEvent (lastChunk=true, artifact)
77
- EQ->>SB: RPC save_task_result (output=payload, p_final=true)
78
- SRV->>EQ: task_done()
79
- EQ->>SB: INSERT events (crew_completed)
80
- ```
81
-
82
-
83
- ## Human-in-the-loop(HITL) 시퀀스
84
- ```mermaid
85
- sequenceDiagram
86
- participant EXE as Your AgentExecutor
87
- participant EQ as ProcessGPTEventQueue
88
- participant SB as Supabase
89
- participant UI as Operator UI
90
-
91
- EXE->>EQ: TaskStatusUpdateEvent (state=input_required)
92
- Note right of EXE: event_type 전송 생략 가능
93
- EQ->>SB: INSERT events (event_type=human_asked, data=질문 payload)
94
- UI->>SB: INSERT events (event_type=human_response, data=사용자 응답)
95
- EXE-->>SB: 선택: fetch_human_response_sync(job_id)
96
- ```
97
-
98
-
99
- ## 친절한 시작 가이드(5분 컷)
100
- 1) 가상환경 + 설치
101
- ```bash
102
- uv venv --python 3.11.9
103
- uv pip install -r requirements.txt
104
- source .venv/Scripts/activate
105
- ```
106
-
107
- 2) .env 준비
108
- - SUPABASE_URL, SUPABASE_KEY 필수
109
- - ENV=dev (개발 환경에서 권장)
110
-
111
- 3) 샘플 서버 실행
112
- ```bash
113
- python sample_server/minimal_server.py | cat
114
- ```
115
-
116
- 4) 이벤트 전송 패턴 이해
117
- - 진행 상태: `TaskStatusUpdateEvent(state=working)` + `new_agent_text_message(text, contextId, taskId)`
118
- - 사용자 입력 요청(HITL): `TaskState.input_required`만 보내면 event_type은 자동 `human_asked`
119
- - 결과물: `TaskArtifactUpdateEvent(lastChunk=True)` + `new_text_artifact(name, desc, text)`
120
-
121
- 5) 저장물 확인 포인트
122
- - `events` 테이블: data에는 래퍼 제거된 순수 payload 저장
123
- - `todolist.output`: 순수 payload 저장, 최종 청크면 `p_final=true`
124
-
125
-
126
- ## 샘플 서버 실행 코드 (친절 버전)
127
- ### A. 가장 간단한 서버(minimal)
128
- ```python
129
- # sample_server/minimal_server.py
130
- import os
131
- import sys
132
- import asyncio
133
- from dotenv import load_dotenv
134
-
135
- # 패키지 루트 경로 추가 (샘플에서만)
136
- sys.path.append(os.path.dirname(os.path.dirname(__file__)))
137
-
138
- from processgpt_agent_sdk.processgpt_agent_framework import ProcessGPTAgentServer
139
- from sample_server.minimal_executor import MinimalExecutor
140
-
141
- async def main():
142
- load_dotenv()
143
- # agent_type은 Supabase의 todolist.agent_orch와 매칭되어야 함
144
- server = ProcessGPTAgentServer(agent_executor=MinimalExecutor(), agent_type="crewai-action")
145
- server.polling_interval = 3 # 초
146
- await server.run()
147
-
148
- if __name__ == "__main__":
149
- try:
150
- asyncio.run(main())
151
- except KeyboardInterrupt:
152
- pass
153
- ```
154
-
155
- - Windows
156
- ```bash
157
- python sample_server/minimal_server.py
158
- ```
159
- - macOS/Linux
160
- ```bash
161
- python3 sample_server/minimal_server.py
162
- ```
163
-
164
- ### B. CLI 옵션이 있는 서버 예시
165
- ```python
166
- # sample_server/crew_ai_dr_agent_server.py
167
- import os
168
- import sys
169
- import asyncio
170
- import click
171
- from dotenv import load_dotenv
172
-
173
- # 패키지 루트 경로 추가 (샘플에서만)
174
- sys.path.append(os.path.dirname(os.path.dirname(__file__)))
175
-
176
- from processgpt_agent_sdk.processgpt_agent_framework import ProcessGPTAgentServer
177
- from sample_server.crew_ai_dr_agent_executor import CrewAIDeepResearchAgentExecutor
178
-
179
- load_dotenv()
180
-
181
- @click.command()
182
- @click.option('--agent-type', default='crew-ai-dr', help='Agent type identifier')
183
- @click.option('--polling-interval', default=5, help='Polling interval in seconds')
184
- def cli_main(agent_type: str, polling_interval: int):
185
- """ProcessGPT Agent Server for CrewAI Deep Research Agent"""
186
-
187
- agent_executor = CrewAIDeepResearchAgentExecutor()
188
- server = ProcessGPTAgentServer(agent_executor=agent_executor, agent_type=agent_type)
189
- server.polling_interval = polling_interval
190
-
191
- print(f"Starting ProcessGPT Agent Server...")
192
- print(f"Agent Type: {agent_type}")
193
- print(f"Polling Interval: {polling_interval} seconds")
194
- print("Press Ctrl+C to stop")
195
-
196
- try:
197
- asyncio.run(server.run())
198
- except KeyboardInterrupt:
199
- print("\nShutting down server...")
200
- server.stop()
201
- except Exception as e:
202
- print(f"Server error: {e}")
203
- sys.exit(1)
204
-
205
- if __name__ == "__main__":
206
- cli_main()
207
- ```
208
-
209
- - 실행
210
- - Windows
211
- ```bash
212
- python sample_server/crew_ai_dr_agent_server.py --agent-type crew-ai-dr --polling-interval 3
213
- ```
214
- - macOS/Linux
215
- ```bash
216
- python3 sample_server/crew_ai_dr_agent_server.py --agent-type crew-ai-dr --polling-interval 3
217
- ```
218
-
219
-
220
- ## 최소 예시(익스큐터)
221
- ```python
222
- # sample_server/minimal_executor.py (요약)
223
- import asyncio
224
- import json
225
- from typing_extensions import override
226
- from a2a.server.agent_execution import AgentExecutor, RequestContext
227
- from a2a.server.events import EventQueue
228
- from a2a.types import TaskStatusUpdateEvent, TaskState, TaskArtifactUpdateEvent
229
- from a2a.utils import new_agent_text_message, new_text_artifact
230
-
231
- class MinimalExecutor(AgentExecutor):
232
- @override
233
- async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
234
- row = context.get_context_data()["row"]
235
- context_id = row.get("root_proc_inst_id") or row.get("proc_inst_id")
236
- task_id = row.get("id")
237
-
238
- payload = {"order_process_activity_order_request_form": {"orderer_name": "안치윤","product_name": "금형세트","order_quantity": "50"}}
239
-
240
- # 1) 진행 상태 이벤트
241
- event_queue.enqueue_event(
242
- TaskStatusUpdateEvent(
243
- status={
244
- "state": TaskState.working,
245
- "message": new_agent_text_message(
246
- json.dumps(payload, ensure_ascii=False),
247
- context_id,
248
- task_id,
249
- ),
250
- },
251
- final=False,
252
- contextId=context_id,
253
- taskId=task_id,
254
- metadata={"crew_type": "action", "event_type": "task_started", "job_id": "job-demo-0001"},
255
- )
256
- )
257
-
258
- await asyncio.sleep(0.1)
259
-
260
- # 2) HITL: 사용자 입력 요청 (event_type 생략해도 자동 human_asked)
261
- event_queue.enqueue_event(
262
- TaskStatusUpdateEvent(
263
- status={
264
- "state": TaskState.input_required,
265
- "message": new_agent_text_message(
266
- json.dumps(payload, ensure_ascii=False),
267
- context_id,
268
- task_id,
269
- ),
270
- },
271
- final=True,
272
- contextId=context_id,
273
- taskId=task_id,
274
- metadata={"crew_type": "action", "job_id": "job-demo-0001"},
275
- )
276
- )
277
-
278
- await asyncio.sleep(0.1)
279
-
280
- # 3) 최종 아티팩트
281
- artifact = new_text_artifact(
282
- name="current_result",
283
- description="Result of request to agent.",
284
- text=json.dumps(payload, ensure_ascii=False),
285
- )
286
- event_queue.enqueue_event(
287
- TaskArtifactUpdateEvent(
288
- artifact=artifact,
289
- lastChunk=True,
290
- contextId=context_id,
291
- taskId=task_id,
292
- )
293
- )
294
- ```
295
-
296
-
297
- ## 서버가 해주는 일(정확한 규칙)
298
- - 메시지/아티팩트 래퍼 제거 → `parts[0].text|content|data` → `root.*` → `top-level` 순서로 텍스트만 추출 후 JSON 파싱하여 저장
299
- - `TaskStatusUpdateEvent` 수신 시
300
- - `status.state == input_required`면 `event_type=human_asked`로 저장(명시값보다 우선)
301
- - 그 외 상태는 `metadata.event_type` 저장(없으면 NULL)
302
- - `TaskArtifactUpdateEvent` 수신 시
303
- - `final` 또는 `lastChunk`가 참이면 최종 저장(`p_final=true`)
304
-
305
-
306
- ## 체크리스트(실패 없는 통합을 위한)
307
- - [ ] .env에 `SUPABASE_URL`, `SUPABASE_KEY` 설정했는가?
308
- - [ ] `requirements.txt` 설치 완료했는가?
309
- - [ ] Supabase에서 제공 SQL(`database_schema.sql`, `function.sql`) 적용했는가?
310
- - [ ] 익스큐터에서 `contextId`, `taskId`를 todolist의 `proc_inst_id`, `id`로 매핑했는가?
311
- - [ ] 상태 이벤트는 `new_agent_text_message`로 만들고 있는가?
312
- - [ ] 최종 아티팩트는 `new_text_artifact` + `lastChunk=True`로 보내고 있는가?
313
- - [ ] HITL 요청은 `TaskState.input_required`만 보내고 있는가?(event_type 생략 가능)
314
-
315
-
316
- ## 트러블슈팅
317
- - 이벤트 미기록
318
- - Supabase URL/Key 재확인, 테이블/권한 확인
319
- - 최종 아티팩트가 최종으로 저장되지 않음
320
- - 익스큐터에서 `lastChunk=True` 또는 `final=True`로 보냈는지 확인
321
- - payload가 래퍼와 같이 저장됨
322
- - 메시지에 `parts[0].text` 또는 `parts[0].root.text`에 JSON 문자열이 들어있는지 확인
323
- - 휴먼인더루프 이벤트 타입 미지정
324
- - `input_required` 상태면 자동 `human_asked`로 저장됨
325
-
326
-
327
- ## 레퍼런스
328
- - 이벤트 유틸: `new_agent_text_message`, `new_text_artifact`
329
- - 서버 진입점: `ProcessGPTAgentServer.run()`
330
- - 컨텍스트 확장: `ProcessGPTRequestContext.prepare_context()`
331
- - 이벤트 저장: `ProcessGPTEventQueue.enqueue_event(event)` → `database.record_event`/`save_task_result`
332
- - 휴먼 응답 조회: `database.fetch_human_response_sync(job_id)`
333
-
334
-
335
- ## 라이선스
336
- 해당 저장소의 라이선스 정책을 따릅니다.
@@ -1,6 +0,0 @@
1
- processgpt_agent_sdk/database.py,sha256=k219S54XwQoGJcKYq6Zr0f7j-Dtrp-v7SpLMRnIgHCI,18979
2
- processgpt_agent_sdk/processgpt_agent_framework.py,sha256=rTX9K-S6G_ZyzGUfIQClmJpoARqT4I51HicNw3i4y4g,16893
3
- process_gpt_agent_sdk-0.3.11.dist-info/METADATA,sha256=SMr1AKnwSkRiYlByB1MjPVLFs-Y003lb8CnoKle9dY8,12201
4
- process_gpt_agent_sdk-0.3.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- process_gpt_agent_sdk-0.3.11.dist-info/top_level.txt,sha256=Xe6zrj3_3Vv7d0pl5RRtenVUckwOVBVLQn2P03j5REo,21
6
- process_gpt_agent_sdk-0.3.11.dist-info/RECORD,,