concatenated_response = f"{task}. Here is the next thought. {response}. "
execution = {
"operation": self.node_name,
"task": task,
"files": input_dict.get("files", []),
"input": task,
"role": role,
"constraint": constraint,
"prompt": user_prompt,
"output": concatenated_response,
"ground_truth": input_dict.get("GT", []),
"format": "natural language"
}
outputs.append(execution)
self.memory.add(self.id, execution)
return outputs
```
%% Cell type:markdown id: tags:
Then we create a custom Chain-of-Thought agent and register it as CustomCOT in the agent registry.
%% Cell type:code id: tags:
```
from swarm.graph import Graph
from swarm.environment.operations.cot_step import CoTStep
from swarm.environment.agents.agent_registry import AgentRegistry
@AgentRegistry.register('CustomCOT')
class CustomCOT(Graph):
def build_graph(self):
num_thoughts = 3
assert num_thoughts >= 2
thoughts = []
for i_thought in range(num_thoughts):
thought = CoTStep(self.domain,
self.model_name,
is_last_step=i_thought==num_thoughts-1)
if i_thought > 0:
thoughts[-1].add_successor(thought)
thoughts.append(thought)
self.input_nodes = [thoughts[0]]
self.output_nodes = [thoughts[-1]]
for thought in thoughts:
self.add_node(thought)
```
%% Cell type:markdown id: tags:
And finally let's create a Swarm with a couple of our custom agents:
%% Cell type:code id: tags:
```
from swarm.graph.swarm import Swarm
swarm = Swarm(["CustomCOT", "CustomCOT"], "gaia")
task = "What is the text representation of the last digit of twelve squared?"
inputs = {"task": task}
answer = await swarm.arun(inputs)
answer
```
%% Output
[32m2024-02-18 14:25:03.364[0m | [1mINFO [0m | [36mswarm.graph.node[0m:[36mlog[0m:[36m160[0m - [1mMemory Records for ID [1;35m6HRq[0m:
[1;34moperation[0m: FinalDecision
[1;34mfiles[0m: []
[1;34msubtask[0m: What is the text representation of the last digit of twelve squared?. Here is the next thought. Calculate twelve squared (12^2), then identify the last digit of the result and convert it to its text representation.. . Here is the next thought. Next step: Compute 12^2 = 144. The last digit is 4. Convert this to its text representation: "four"..
Reference information for CoTStep:
----------------------------------------------
FINAL ANSWER: four
FINAL ANSWER: four
----------------------------------------------
Provide a specific answer. For questions with known answers, ensure to provide accurate and factual responses. Avoid vague responses or statements like 'unable to...' that don't contribute to a definitive answer. For example: if a question asks 'who will be the president of America', and the answer is currently unknown, you could suggest possibilities like 'Donald Trump', or 'Biden'. However, if the answer is known, provide the correct information.