You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

overview.md 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Overview
  2. This section provides the background and overview of AGNext.
  3. ## Agent and Multi-Agent Application
  4. An agent is a software entity that
  5. communicates via messages, maintains a state,
  6. and performs actions in response to messages or a change in its state.
  7. Actions can result in changes to the agent's state and external effects,
  8. for example, updating message history, sending a message, executing code,
  9. or making external API calls.
  10. A wide variety of software applications can be modeled as a collection of independent
  11. agents that communicate with each other:
  12. sensors on a factory floor,
  13. distributed services powering web applications,
  14. business workflows involving multiple stakeholders,
  15. and more recently, artificial intelligence (AI) agents powered by language models
  16. (e.g., GPT-4) that can write code and interact with
  17. other software systems.
  18. We refer to them as multi-agent applications.
  19. ```{note}
  20. AI agents make use of language models as part of
  21. their software stacks to perform actions.
  22. ```
  23. In a multi-agent application, agents can live in the same process, on the same machine,
  24. or on different machines and across organizational boundaries.
  25. They can be implemented using different AI models, instructions, and programming languages.
  26. They can collaborate and work toward a common goal.
  27. Each agent is a self-contained unit:
  28. developers can build, test and deploy it independently, and reuse it for different scenarios.
  29. Agents are composable: simple agents can form complex applications.
  30. ## AGNext Architecture
  31. AGNext is a framework for building multi-agent applications with AI agents.
  32. At the foundation level, it provides a runtime envionment to facilitate
  33. communication between agents, manage their identities and lifecycles,
  34. and enforce security and privacy boundaries.
  35. ### Runtime Architecture
  36. The following diagram shows the runtime architecture of AGNext.
  37. ![AGNext Runtime](agnext-architecture.svg)
  38. Agent communicate via messages through the runtime.
  39. A runtime, as shown in the diagram,
  40. can consist of a hosted runtime and multiple worker runtimes.
  41. Agents in worker runtimes communicate with other agents via the hosted runtime
  42. through gateways, while agents in the hosted runtime communicate
  43. directly with each other.
  44. Most single-process applications need only an embedded hosted runtime.
  45. AGNext also offers a set of unopinionated and extensible components for building AI agents.
  46. It does not prescribe an abstraction for AI agents, rather, it provides
  47. a minimal base layer that can be extended to suit the application's needs.
  48. Developers can build agents quickly by using the provided components including
  49. type-routed agent, AI model clients, tools for AI models, code execution sandboxes,
  50. memory stores, and more.
  51. Developers can also make use of the provided multi-agent patterns to build
  52. orchestrated workflows, group chat systems, and more.
  53. ### API Layers
  54. The API consists of the following layers:
  55. - {py:mod}`agnext.core`
  56. - {py:mod}`agnext.application`
  57. - {py:mod}`agnext.components`
  58. The following diagram shows the relationship between the layers.
  59. ![AGNext Layers](agnext-layers.svg)
  60. The {py:mod}`agnext.core` layer defines the
  61. core interfaces and base classes for agents, messages, and runtime.
  62. This layer is the foundation of the framework and is used by the other layers.
  63. The {py:mod}`agnext.application` layer provides concrete implementations of
  64. runtime and utilities like logging for building multi-agent applications.
  65. The {py:mod}`agnext.components` layer provides reusable components for building
  66. AI agents, including type-routed agents, AI model clients, tools for AI models,
  67. code execution sandboxes, and memory stores.
  68. The layers are loosely coupled and can be used independently. For example,
  69. you can swap out the runtime in the {py:mod}`agnext.application` layer with your own
  70. runtime implementation.
  71. You can also skip the components in the {py:mod}`agnext.components` layer and
  72. build your own components.
  73. ## AGNext Application Stack
  74. AGNext is designed to be an unopinionated framework that can be used to build
  75. a wide variety of multi-agent applications. It is not tied to any specific
  76. agent abstraction or multi-agent pattern.
  77. The following diagram shows the AGNext application stack.
  78. ![AGNext Application Stack](agnext-application-stack.svg)
  79. At the bottom of the stack is the base messaging and routing facilities that
  80. enable agents to communicate with each other. These are managed by the
  81. agent runtime, and for most applications, developers only need to interact
  82. with the high-level APIs provided by the runtime (see [Agent and Agent Runtime](../getting-started/agent-and-agent-runtime.ipynb)).
  83. On top of the communication stack, developers need to define the
  84. types of the messages that agents exchange. A set of message types
  85. forms a behavior contract that agents must adhere to, and the
  86. implementation of the contracts determines how agents handle messages.
  87. The behavior contract is sometimes referred to as the message protocol.
  88. It is the developer's responsibility to implement the behavior contract.
  89. Multi-agent patterns are design patterns that emerge from behavior contracts
  90. (see [Multi-Agent Design Patterns](../getting-started/multi-agent-design-patterns.md)).
  91. ### An Example Application
  92. Consider a concrete example of a multi-agent application for
  93. code generation. The application consists of three agents:
  94. Coder Agent, Executor Agent, and Reviewer Agent.
  95. The following diagram shows the data flow between the agents,
  96. and the message types exchanged between them.
  97. ![Code Generation Example](agnext-code-gen-example.svg)
  98. In this example, the behavior contract consists of the following:
  99. - `CodingTaskMsg` message from application to the Coder Agent
  100. - `CodeGenMsg` from Coder Agent to Executor Agent
  101. - `ExecutionResultMsg` from Executor Agent to Reviewer Agent
  102. - `ReviewMsg` from Reviewer Agent to Coder Agent
  103. - `CodingResultMsg` from the Reviewer Agent to the application
  104. The behavior contract is implemented by the agents' handling of these messages. For example, the Reviewer Agent listens for `ExecutionResultMsg`
  105. and evaluates the code execution result to decide whether to approve or reject,
  106. if approved, it sends a `CodingResultMsg` to the application,
  107. otherwise, it sends a `ReviewMsg` to the Coder Agent for another round of
  108. code generation.
  109. This behavior contract is a case of a multi-agent pattern called Reflection,
  110. where a generation result is reviewed by another round of generation,
  111. to improve the overall quality.