Reference:Datawhale wow agent day13
Agent#
In the view of MetaGPT, an agent can be imagined as a digital person in the environment, where
Agent = Large Language Model (LLM) + Observation + Thinking + Action + Memory
This formula summarizes the essential functions of an agent. To understand each component, let's draw an analogy with humans:
- Large Language Model (LLM): The LLM serves as the "brain" of the agent, enabling it to process information, learn from interactions, make decisions, and execute actions.
- Observation: This is the agent's perception mechanism, allowing it to sense its environment. The agent may receive a range of signals, such as text messages from another agent, visual data from surveillance cameras, or audio from customer service recordings. These observations form the basis for all subsequent actions.
- Thinking: The thinking process involves analyzing observations and memory content and considering possible actions. This is the internal decision-making process of the agent, which may be driven by the LLM.
- Action: These are the explicit responses of the agent to its thinking and observations. Actions can involve generating code using the LLM or manually predefined operations, such as reading local files. Additionally, the agent can perform operations using tools, including searching the internet for weather or performing mathematical calculations with a calculator.
- Memory: The agent's memory stores past experiences. This is crucial for learning, as it allows the agent to reference previous outcomes and adjust future actions accordingly.
Multi-Agent#
A multi-agent system can be viewed as a society of agents, where
Multi-Agent = Agent + Environment + Standard Operating Procedures (SOP) + Communication + Economy
These components each play an important role:
- Agent: Based on the individual definitions above, agents in a multi-agent system work collaboratively, each possessing unique LLMs, observations, thinking, actions, and memories.
- Environment: The environment is the common space where agents exist and interact. Agents observe important information from the environment and publish the outputs of their actions for other agents to use.
- Standard Operating Procedures (SOP): These are established procedures that manage agent actions and interactions, ensuring orderly and efficient operation within the system. For example, in the SOP for car manufacturing, one agent welds car parts while another installs cables, maintaining the orderly operation of the assembly line.
- Communication: Communication is the process of information exchange between agents. It is crucial for collaboration, negotiation, and competition within the system.
- Economy: This refers to the value exchange system in a multi-agent environment, determining resource allocation and task priorities.
Task#
For each task, at least two points must be clarified: the goal and the expectations. Both the goal and expectations can be described in natural language.
Other aspects that need clarification include context, callbacks, outputs, and tools used.
A callback can be a Python function. The tools used can be a Python list.
You can use Pydantic to constrain the output appropriately, transforming the vague output of the large model into a structured output.
Tools#
A commonly used tool is a search engine. For example, Google's Serper. What is the domestic alternative?
There are also web scraping tools.
Create a new Jupyter notebook and copy the following code into it:
import asyncio
from metagpt.roles import (
Architect,
Engineer,
ProductManager,
ProjectManager,
)
from metagpt.team import Team
async def startup(idea: str):
company = Team()
company.hire(
[
ProductManager(),
Architect(),
ProjectManager(),
Engineer(),
]
)
company.invest(investment=3.0)
company.run_project(idea=idea)
await company.run(n_round=5)
In the code above, we can directly use the default roles. The actions that these roles need to perform have already been written, so just use them as is.
Then execute the following line of code to get started:
|Python<br>await startup(idea="Develop a question-answering program")|
| :- |