agents.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { api } from './client'
  2. export interface Agent {
  3. id: string
  4. name: string
  5. description: string
  6. current_version: number
  7. status: string
  8. tags: string[]
  9. config: Record<string, unknown>
  10. agent_dir: string
  11. work_dir: string
  12. source_dir: string
  13. run_dir: string
  14. kb_ids: string[]
  15. kb_search_mode: string
  16. created_at: string
  17. updated_at: string
  18. }
  19. export interface AgentKnowledge {
  20. kb_ids: string[]
  21. kb_search_mode: string
  22. knowledge_bases: Array<{
  23. id: string
  24. name: string
  25. root_dir: string
  26. description: string
  27. }>
  28. }
  29. export interface Run {
  30. id: string
  31. agent_id: string
  32. status: string
  33. input: string
  34. output: string
  35. duration_ms: number
  36. input_tokens: number
  37. output_tokens: number
  38. cache_read_tokens: number
  39. cache_creation_tokens: number
  40. cost_usd: number | null
  41. steps: number
  42. workspace_path: string | null
  43. error: string | null
  44. created_at: string
  45. }
  46. export interface WorkspaceFile {
  47. name: string
  48. path: string // relative to workspace root
  49. size: number
  50. modified: number
  51. }
  52. export interface MemoryEntry {
  53. key: string
  54. content: string
  55. tier: string // working | episodic | semantic
  56. tags: string[]
  57. source: string
  58. created_at: number
  59. expires_at: number
  60. access_count: number
  61. }
  62. // Persistent Memory (Letta 3-layer)
  63. export type CoreMemory = Record<string, unknown>
  64. export interface RecallEntry {
  65. run_id: string
  66. input: string
  67. output: string
  68. ts: string
  69. }
  70. export const agentsApi = {
  71. list: () => api.get<{ agents: Agent[] }>('/agents'),
  72. get: (id: string) => api.get<Agent>(`/agents/${id}`),
  73. create: (body: {
  74. name: string
  75. description: string
  76. config: Record<string, unknown>
  77. tags: string[]
  78. agent_dir?: string
  79. work_dir?: string
  80. source_dir?: string
  81. run_dir?: string
  82. kb_ids?: string[]
  83. kb_search_mode?: string
  84. }) => api.post<{ agent_id: string }>('/agents', body),
  85. update: (id: string, body: {
  86. config: Record<string, unknown>
  87. agent_dir?: string
  88. work_dir?: string
  89. source_dir?: string
  90. run_dir?: string
  91. changelog?: string
  92. kb_ids?: string[]
  93. kb_search_mode?: string
  94. }) => api.put(`/agents/${id}`, body),
  95. delete: (id: string) => api.delete(`/agents/${id}`),
  96. runs: (id: string, limit = 50) =>
  97. api.get<{ runs: Run[] }>(`/agents/${id}/runs?limit=${limit}`),
  98. // Sub-agent (multi-agent orchestrator) config file
  99. subAgentConfig: (agentId: string, subName: string) =>
  100. api.get<{
  101. sub_name: string
  102. tool?: string
  103. path: string | null
  104. rel_path?: string
  105. inline: boolean
  106. content: string
  107. }>(`/agents/${agentId}/subagents/${encodeURIComponent(subName)}/config`),
  108. // Workspace file browsing
  109. workspaceFiles: (agentId: string, runId: string) =>
  110. api.get<{ files: WorkspaceFile[]; workspace_path: string }>(
  111. `/agents/${agentId}/runs/${runId}/workspace`
  112. ),
  113. workspaceDownloadUrl: (agentId: string, runId: string, filePath: string) =>
  114. `/api/v1/agents/${agentId}/runs/${runId}/workspace/${filePath}`,
  115. // Legacy memory management (tier-based MemoryService)
  116. memory: (agentId: string) =>
  117. api.get<{ entries: MemoryEntry[]; count: number }>(`/agents/${agentId}/memory`),
  118. deleteMemory: (agentId: string, key: string) =>
  119. api.delete(`/agents/${agentId}/memory/${key}`),
  120. // Persistent Memory — Layer 1: Core Memory
  121. coreMemory: (agentId: string) =>
  122. api.get<{ core: CoreMemory; agent_dir: string }>(`/agents/${agentId}/memory/core`),
  123. updateCoreMemory: (agentId: string, core: CoreMemory) =>
  124. api.put<{ core: CoreMemory }>(`/agents/${agentId}/memory/core`, core),
  125. clearCoreMemory: (agentId: string) =>
  126. api.delete<{ cleared: boolean }>(`/agents/${agentId}/memory/core`),
  127. // Persistent Memory — Layer 2: Recall Log
  128. recallMemory: (agentId: string, n = 20) =>
  129. api.get<{ entries: RecallEntry[]; total: number }>(`/agents/${agentId}/memory/recall?n=${n}`),
  130. // Agent-KB linking
  131. getKBs: (agentId: string) =>
  132. api.get<AgentKnowledge>(`/agents/${agentId}/knowledge`),
  133. updateKBs: (agentId: string, kb_ids: string[], kb_search_mode: string) =>
  134. api.put<{ kb_ids: string[]; kb_search_mode: string }>(
  135. `/agents/${agentId}/knowledge`, { kb_ids, kb_search_mode }
  136. ),
  137. }