agent.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { nanoid } from 'nanoid';
  6. import { FlowNodeBaseType } from '@flowgram.ai/fixed-layout-editor';
  7. import { LLMNodeRegistry } from '../llm';
  8. import { defaultFormMeta } from '../default-form-meta';
  9. import { FlowNodeRegistry } from '../../typings';
  10. import iconRobot from '../../assets/icon-robot.svg';
  11. import { ToolNodeRegistry } from './tool';
  12. import { MemoryNodeRegistry } from './memory';
  13. let index = 0;
  14. export const AgentNodeRegistry: FlowNodeRegistry = {
  15. type: 'agent',
  16. extend: FlowNodeBaseType.SLOT,
  17. info: {
  18. icon: iconRobot,
  19. description: 'AI Agent.',
  20. },
  21. formMeta: defaultFormMeta,
  22. onAdd(ctx, from) {
  23. return {
  24. id: `agent_${nanoid(5)}`,
  25. type: 'agent',
  26. blocks: [
  27. {
  28. id: `agentLLM_${nanoid(5)}`,
  29. type: 'agentLLM',
  30. blocks: [LLMNodeRegistry.onAdd!(ctx, from)],
  31. },
  32. {
  33. id: `agentMemory_${nanoid(5)}`,
  34. type: 'agentMemory',
  35. blocks: [MemoryNodeRegistry.onAdd!(ctx, from)],
  36. },
  37. {
  38. id: `agentTools_${nanoid(5)}`,
  39. type: 'agentTools',
  40. blocks: [ToolNodeRegistry.onAdd!(ctx, from)],
  41. },
  42. ],
  43. data: {
  44. title: `Agent_${++index}`,
  45. outputs: {
  46. type: 'object',
  47. properties: {
  48. result: { type: 'string' },
  49. },
  50. },
  51. },
  52. };
  53. },
  54. };