You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to autogen and I am trying out a new use case, with the help of multiple function tools. But now I am in confusion about how to achieve this. I have a function tool called kafka_consumer, which will keep listening to the server for new values. So my user_proxy agent will register this tool, I also have another tool called alert_tool that will also be registered, so in the Kafka consumer tool when an even number is received it should be able to send this back to the user proxy agent so that the user proxy agent can make another trigger call to send an alert using the send_alert tool. This should not close the initial Kafka consumer tool. so is there a way the tool can communicate back to the Agent and the agent can route the output from the tool to another function? the catch is that it should not exit my Kafka consumer tool, and an alert should be sent whenever the number is even. The provided is my code snippet, and this is too dependent on a single function tool:
def send_alert(api: str, number: int):
"""Api to send alert
"""
url = f"{api}?number={number}"
try:
# Perform the GET request to the API
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
print(f"API Response: {response.text}")
else:
print(
f"Failed to call API. Status code: {response.status_code}, Message: {response.text}"
)
except Exception as e:
print(f"An error occurred: {e}")
@user_proxy.register_for_execution()
@coder.register_for_llm(description="Create a Kafka consumer for listening to a topic")
def KafkaConsumerTool(
bootstrap_servers: Annotated[str, "Kafka bootstrap server for listening data from"],
topic: Annotated[str, "Topic used in the kafka consumer for listening."],
api: Annotated[str, "Api endpoint for sending alert"]
) -> str:
"""Kafka consumer tool
"""
# Set up the Kafka consumer
consumer = KafkaConsumer(
topic,
bootstrap_servers=bootstrap_servers,
auto_offset_reset="earliest",
group_id="even-number-consumers",
)
# Consume messages
for message in consumer:
number = int(message.value.decode("utf-8"))
if number % 2 == 0:
send_alert(api=api, number=number)
with Cache.disk() as cache:
user_proxy.initiate_chat(
coder,
message="create a Kafka consumer and listen to the Kafka server that is \
running on`localhost:9092` and topic `number` and print the result \
send an alert to the api `http://localhost:5000/number`",
cache=cache,
)
I want a new function tool to send alerts that perform a callback when receiving an even number without breaking the Kafka consumer code. Can someone point out how to achieve this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I am new to autogen and I am trying out a new use case, with the help of multiple function tools. But now I am in confusion about how to achieve this. I have a function tool called kafka_consumer, which will keep listening to the server for new values. So my user_proxy agent will register this tool, I also have another tool called alert_tool that will also be registered, so in the Kafka consumer tool when an even number is received it should be able to send this back to the user proxy agent so that the user proxy agent can make another trigger call to send an alert using the send_alert tool. This should not close the initial Kafka consumer tool. so is there a way the tool can communicate back to the Agent and the agent can route the output from the tool to another function? the catch is that it should not exit my Kafka consumer tool, and an alert should be sent whenever the number is even. The provided is my code snippet, and this is too dependent on a single function tool:
I want a new function tool to send alerts that perform a callback when receiving an even number without breaking the Kafka consumer code. Can someone point out how to achieve this?
Thanks for the help in advance....
Beta Was this translation helpful? Give feedback.
All reactions