1.contexts
roots or stems of plantsqiang~follow sth closelyOpenAILightweight multi-agent framework released two weeks agoSwarmSo I wanted to dig a little deeper, run the official examples provided, organize and summarize some insights~
The source code is very simple, so you can read a little, this article uses thegpt-4o-miniVerify, if you want to use it for freegpt-4o-mini, can be communicated by private message.
Ps: Once it was released, it was on theXgave rise toSwarmAlleged plagiarism, but eating my heart out, I'm still focused on the technology within itself.
2.synopsis
SwarmThe project is a lightweightmulti-agentOrchestration framework, currently mainly for experimental and teaching purposes, not for production use。
Swarmspecialize in makingagentCoordination and operation become lightweight, highly controllable and easy to test.
There are two main abstraction modules:Agentcap (a poem)handoffs(switch modes or data streams),Agentencapsulatesinstructionscap (a poem)toolsand can choose to hand over the conversation to another agent at any time.
3. Applicable Scenarios
Ideal for a large number of separate functions and instructions that are difficult to integrate into a singlepromptscenarios, but rather the separate functions and commands are passed through theagent, functions, toolsetc. to link.
4. Swarmcore module
4.1 ()
alikeopenai(used form a nominal expression)chat completions apihit the nail on the headcreate()function that receives and returns themessagesand does not save any state between calls. Note that this method also handlesAgentFunction execution, switching, context variable references, and the ability to have multiple rounds of dialog before returning the final output.
Its core implements the following loop:
(1) currentAgentCalling the model returns results
(2) Execute the tool call and save the result
(3) Switching agents when necessary
(4) Update context variables as necessary
(5) If there are no new function calls, return the
When the method finishes executing, it returns aResponse, which contains the status of all relevant updates, including the newmessages, Last Calledagentand the latest context variablescontext_variables。
4.2 Agents
AgentSimply encapsulates a set ofinstructionscap (a poem)functionsand has the ability to hand over execution to anotheragentabilities. Theseinstructionscap (a poem)functionsCan be used to represent very specific workflows or steps.
Instructionswill be transformed directly into a dialog ofsystemTip, at any time, there will only be activeagent(used form a nominal expression)instructions。
instructionscan be a plain string or a function that returns a string that can choose acontext_variablesparameter, which in turn is passed into the()Center.
Swarm(used form a nominal expression)AgentYou can directly call thepythonfunction, usuallyfunctionshould return astr, but it can also be aAgentIf you returnAgentthen the execution is transferred to thatAgent. IfAgentAn error occurs in the function call of the function, and the error response is added to the chat toAgentcan be recovered normally. If theAgentCall multiple functions and they will be in order.
4.3 switch modes or data streamsAgentand update context variables
anagentThis can be accomplished by adding thefunctionto hand it over to another agent by returning it in the It is also possible to hand it over to another agent by returning the more completeResultobject to update thecontext_variables
5. real combat
This hands-on mainly runs the examples that come with the projectairline. This example provides a good illustration ofSwarmThe operating mechanism of the
5.1 AgentThe overall interaction flow between
The interaction steps are as follows:
- The first step is to recognize the intent.Agent, determines whether to process a flight change or a lost baggage and passes it through thetransfer_to_flight_modification, transfer_to_lost_baggageSwitch to the correspondingAgent
- If it's a flight change, it further determines whether it's a flight cancellation or a flight replacement, and if it's a flight cancellation, passes thetransfer_to_flight_cancelSwitch to”flight cancelationAgent”To carry out the processing, theAgentSupport for refunds, redeeming flight credits, feedback to supervisor, issue resolved, switch to intent recognitionAgentet al. (and other authors)5method; in the case of flight replacement, bytransfer_to_flight_changeSwitch to”Flight changesAgent”shouldAgentSupports Replacement Validation, Replacement Success, Feedback to Supervisor, Problem Resolved, Switch to Intent RecognitionAgentet al. (and other authors)5A method.
- If it is a baggage related issue, switch to "Loss of baggageAgent”shouldAgentIncludes baggage search, feedback to supervisor, problem solved, switch to intent recognitionAgentet al. (and other authors)4one way
5.2 real-world effect
included among theseUserIt's my output.,[2024...]is the printed log.Triage Agent、Flight Modification Agent、Flight cancel traversalcounterpartAgentor methodThe result returned after calling the big model.
Starting Swarm CLI �� User: I want a refund. [2024-10-22 09:38:14] Ending turn. Triage Agent: Can you please provide us with your flight number and the reason you wish to refund your ticket? User: The flight number is1919I've got a bit of a schedule conflict. [2024-10-22 09:38:48] Processing tool call: transfer_to_flight_modification with arguments {} [2024-10-22 09:38:49] Processing tool call: transfer_to_flight_cancel with arguments {} [2024-10-22 09:38:50] Ending turn. Triage Agent: transfer_to_flight_modification() Flight Modification Agent: transfer_to_flight_cancel() Flight cancel traversal: The flight number you mentioned is1919. Please confirm if you are indeed canceling this flight. If so, I will proceed with the process. User: yea [2024-10-22 09:38:57] Ending turn. Flight cancel traversal: Would you like to request a refund or would you like to receive a flight credit? User: Get a refund. [2024-10-22 09:39:05] Processing tool call: initiate_refund with arguments {} [2024-10-22 09:39:06] Ending turn. Flight cancel traversal: initiate_refund() Flight cancel traversal: Your refund request has been processed and the refund will be issued on3-5It will be completed within one working day. Please be patient. Do you have any other questions? User: No, thank you. [2024-10-22 09:39:16] Processing tool call: case_resolved with arguments {} [2024-10-22 09:39:20] Ending turn. Flight cancel traversal: case_resolved() Flight cancel traversal: Thank you for contacting us! Please feel free to contact us if you have any questions in the future. Have a wonderful day! User: |
6.summarize
One word is enough.~
This article focuses onOpenAIexpand one's financial resourcesmulti-agentorganizing planswarmPresentation, including its core componentsAgent, instructions,functionsMultipleAgentHow to switch between them, and for whichexamplesFor validation, the framework and source code is very simple, so watchers can try it out for themselves.
Multi-agentThe applicable scenarios are very rich, such as customer service, workflow processing, etc.
If you want to get free access toopenaiThe watchers can communicate with each other by private message.
7.consultation
(1) Swarmrepository: /openai/swarm