@@ -71,12 +71,15 @@ class Agent:
71
71
},
72
72
}
73
73
74
- _default_act_prompt = """
74
+ _default_self_introduction_prompt = """
75
75
Informations about yourself:
76
76
{agent_informations}
77
77
78
78
Your interactions:
79
79
{interactions}
80
+ """
81
+
82
+ _default_act_prompt = """{self_introduction}
80
83
81
84
Given the above information, think about what you should do next.
82
85
@@ -127,6 +130,8 @@ def __init__(self, **kwargs):
127
130
self .agent_informations ["bio" ] = Agent ._generate_agent_bio (self .agent_informations )
128
131
129
132
self ._interaction_manager .register_agent (self )
133
+
134
+ self ._self_introduction_prompt = deepcopy (Agent ._default_self_introduction_prompt )
130
135
self ._act_prompt = deepcopy (Agent ._default_act_prompt )
131
136
132
137
self ._actions = deepcopy (Agent ._default_actions )
@@ -315,9 +320,13 @@ def act(self) -> str:
315
320
# [TALK][AGENT_ID][CONTENT]: Talk to the agent with the given ID. Note that you must the agent ID, not the agent name. (i.e [TALK][123][Hello!])
316
321
# [CHATGPT][CONTENT]: Use ChatGPT. (i.e [CHATGPT][Hello!])
317
322
318
- prompt = self ._act_prompt .format (
323
+ self_introduction = self ._self_introduction_prompt .format (
319
324
agent_informations = self .agent_informations ,
320
325
interactions = self .get_interactions (),
326
+ )
327
+
328
+ prompt = self ._act_prompt .format (
329
+ self_introduction = self_introduction ,
321
330
actions = "\n " .join ([f"{ action ['format' ]} : { action ['prompt' ]} (i.e { action ['example' ]} )" for action in self ._actions .values ()]),
322
331
list_of_actions = list (self ._actions .keys ()),
323
332
)
@@ -439,6 +448,39 @@ def think(self, message: str) -> None:
439
448
"message" : message ,
440
449
}
441
450
451
+ def ask (self , message : str ) -> None :
452
+ """
453
+ Ask the agent a question and receive a contextually aware response.
454
+
455
+ The agent considers its characteristics and interaction history when formulating
456
+ the response, maintaining consistency with its persona.
457
+
458
+ Note: The agent will not save the question nor the response in its interaction history.
459
+
460
+ Args:
461
+ message (str): The question to ask the agent.
462
+
463
+ Returns:
464
+ str: The agent's response to the question.
465
+ """
466
+
467
+ prompt = self ._self_introduction_prompt .format (
468
+ agent_informations = self .agent_informations ,
469
+ interactions = self .get_interactions (),
470
+ )
471
+
472
+ prompt += f"\n You are asked the following question: { message } . Answer the question as best as you can."
473
+
474
+ response = llm_client .chat .completions .create (
475
+ model = f"{ config .llm_provider } :{ config .llm_model } " ,
476
+ messages = [
477
+ {"role" : "user" , "content" : prompt },
478
+ ],
479
+ temperature = 0.4 ,
480
+ )
481
+
482
+ return response .choices [0 ].message .content
483
+
442
484
def add_new_action (self , action_descriptor : dict [str , str ], action_function : Callable [[Agent , str ], str | dict ]) -> None :
443
485
"""
444
486
Add a new action to the agent's capabilities.
0 commit comments