how we can pass output of one function to another function with agents????? #5502
Unanswered
Zohreh6384NKH
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@Zohreh6384NKH I would never trust any model to perform copy & pasting numbers or text values when those values are required to be exactly the same. If any step like this is involved in your workflow, please consider ways to do it without using models. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
this is my code.the idea is calling sum_divide function and return the result as 'h' .then use this h in the second function and return the result. but the problem is i get different result from h.once i get h =30 wich is correct. the second time i execute the function i get different result from h.even though I emphasise use the exact result from the first function as h.
llm_config = {
"config_list": [
{
"model": "llama3.1",
"api_type": "ollama",
"client_host": "http://localhost:11434",
"timeout": 120,
"cache_seed": None,
}
]
}
UserProxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
max_consecutive_auto_reply=1,
code_execution_config=False,
)
Assistant_1 = AssistantAgent(
name="assistant_1",
system_message="Step 1: Call the 'sum_divide' function with a=100 and b=50. "
"Store the result as 'h' exactly as returned by the function. "
"only use the function you have been provided with",
llm_config=llm_config,
)
Assistant_2 = AssistantAgent(
name="assistant_2",
system_message="Step 2: Use the exact value of 'h' from the previous step to call the 'subtract_multiply' function. "
"Call 'subtract_multiply' with c=80 and d=40 using the value of 'h' exactly as provided (do not modify it or guess a new value). "
"Return the final result. only use the function you have been provided",
llm_config=llm_config,
)
Define the sum_divide function
@UserProxy.register_for_execution()
@Assistant_1.register_for_llm(description="Sum two numbers and divide by 5.")
def sum_divide(a: float, b: float) -> float:
"""
Sums two numbers and divides the result by 5.
Define the subtract_multiply function
@UserProxy.register_for_execution()
@Assistant_2.register_for_llm(description="Subtract two numbers and multiply by the result from 'sum_divide'.")
def subtract_multiply(c: float, d: float, h: float) -> float:
"""
Subtracts two numbers and multiplies the result by the output of the 'sum_divide' function.
Initiate the chats with strict linking of 'h'
UserProxy.initiate_chats(
[
{
"recipient": Assistant_1,
"message": "Step 1: Call 'sum_divide' function with a=100 and b=50, store the result as 'h', and return it.",
"executor_function": sum_divide,
"summary_method": "last_msg",
},
{
"recipient": Assistant_2,
"message": "Step 2: Use the value of 'h' from 'sum_divide' to call 'subtract_multiply' with c=80 and d=40. Return the result.",
"executor_function": subtract_multiply,
"summary_method": "last_msg",
}
]
) this is the result after running the code:
tep 1: Call 'sum_divide' function with a=100 and b=50, store the result as 'h', and return it.
assistant_1 (to user_proxy):
***** Suggested tool call (ollama_func_2628): sum_divide *****
Arguments:
{"a": 100, "b": 50}
***** Response from calling tool (ollama_func_2628) *****
30.0
assistant_1 (to user_proxy):
***** Suggested tool call (ollama_func_1119): sum_divide *****
Arguments:
{"a": 100, "b": 50}
Starting a new chat....
user_proxy (to assistant_2):
Step 2: Use the value of 'h' from 'sum_divide' to call 'subtract_multiply' with c=80 and d=40. Return the result.
Context:
assistant_2 (to user_proxy):
***** Suggested tool call (ollama_func_9168): subtract_multiply *****
Arguments:
{"c": 80, "d": 40, "h": 20}
***** Response from calling tool (ollama_func_9168) *****
800
assistant_2 (to user_proxy):
***** Suggested tool call (ollama_func_9264): subtract_multiply *****
Arguments:
{"c": 80, "d": 40, "h": 20}
Beta Was this translation helpful? Give feedback.
All reactions