Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After finding the function, sdk is not able to send further messages. #8

Open
2 tasks done
abhifetch opened this issue Jul 18, 2024 · 4 comments
Open
2 tasks done
Assignees

Comments

@abhifetch
Copy link

abhifetch commented Jul 18, 2024

Prerequisites

  • I checked the documentation and found no answer to my problem
  • I checked the existing issues and made sure there are no similar bug reports

Category

Bug (unexpected behavior)

Expected Behavior

It should come up with the latest messages in the session.

Observed Behavior

It endlessly goes into loop after saying '✨I am on it and will start working on the 'maths tutor GCSE' task.'

10:44:37 INFO ai_engine_sdk1:
🤖 Processing

10:44:39 DEBUG ai_engine_sdk1: No messages: 16 times in a row
10:44:39 DEBUG client:

📤 Request triggered : GET https://agentverse.ai/v1beta1/engine/chat/sessions/aba383b2-fbab-4d51-949d-f2fe2965834c/new-messages?last_message_id=1e5ccf24-9529-443c-81d0-90b41d531c9f
10:44:39 DEBUG client: body=None
10:44:39 DEBUG client: ---------------------------

To Reproduce

using the following script (ai-engine-sdk-py/examples/run_example.py):

import os
from dotenv import load_dotenv
import asyncio
import logging
import sys
from time import sleep
from ai_engine_sdk import (
    AiEngine,
    is_agent_message,
    is_ai_engine_message,
    is_confirmation_message,
    is_stop_message,
    is_task_selection_message, TaskSelectionMessage
)
from ai_engine_sdk import ApiBaseMessage, FunctionGroup

# Load environment variables from the .env file
load_dotenv()

# Access the AV API key from the environment variables
api_key = os.getenv("AV_API_KEY")

logger = logging.getLogger(__name__)

interaction_user_prompt_header = f"\n\n🤖 Interaction time"

async def main():
    logger.debug("🚀 Starting example execution")
    ai_engine = AiEngine(api_key)

    function_groups: list[FunctionGroup] = await ai_engine.get_function_groups()

    
    my_group = next(
	(g for g in function_groups if g.name == "My Functions"), 
	None
)

    session = await ai_engine.create_session(function_group=my_group.uuid)
    default_objective: str = "Find a flight to warsaw."

    logger.info(interaction_user_prompt_header)
    objective = input(f"\n🎯 What is your objective [default: {default_objective}]: ") or default_objective
    await session.start(objective)

    try:
        empty_count = 0
        session_ended = False

        while empty_count < 100:
            messages: list[ApiBaseMessage] = await session.get_messages()
            if len(messages) == 0:
                empty_count += 1
            else:
                empty_count = 0

            message: ApiBaseMessage
            for message in messages:
                if is_task_selection_message(message.type):
                    task_selection_message: TaskSelectionMessage = message

                    logger.info(interaction_user_prompt_header)
                    print("Please select a key from the list below:\n")
                    for _, option in task_selection_message.options.items():
                        print(f"➡ 🔑 {option.key}  ->  🧰 {option.title}")
                    option_key = str(input("\nEnter task key: "))

                    # check the index
                    if option_key not in task_selection_message.options.keys():
                        raise Exception(f"🔴 Invalid task number.\n You selected: {option_key}")
                    logger.debug(option_key)
                    await session.submit_task_selection(message, [task_selection_message.options[option_key]])
                    del task_selection_message
                elif is_agent_message(message):
                    logger.info(interaction_user_prompt_header)
                    print(message.text.capitalize())
                    response = input("✍ (enter to skip): ")
                    if response == "exit":
                        break

                    if response != "":
                        await session.submit_response(message, response)
                elif is_ai_engine_message(message):
                    logger.info(f"\n 🤖 ℹ Informative message \n\n ---> ✨{message.text}")
                    sleep(3.5)
                elif is_confirmation_message(message.type):
                    logger.info(interaction_user_prompt_header)
                    print("Confirm:", message.payload)
                    response = input("\nPress enter to confirm, otherwise explain issue:\n")

                    if response == "":
                        await session.submit_confirmation(message)
                    else:
                        await session.reject_confirmation(message, response)
                elif is_stop_message(message):

                    logger.info("\n 👋 Session has ended, thanks! ")
                    session_ended = True
                    break

            # if the session has concluded then break
            if session_ended:
                break

            logger.info(f"\n🤖 Processing\n")
            sleep(1.5)
            logger.debug(f"No messages: {empty_count} times in a row")

    except Exception as e:
        logger.debug(f"Unhandled exception: {e}")
        print("Error", e)
        raise e
    finally:
        # clean up the session
        await session.delete()


if __name__ == "__main__":
    logging.basicConfig(
        stream=sys.stdout,
        level=logging.DEBUG,  # Get more information, explore technical details
        # level=logging.INFO,  # Smooth experience
        format='%(asctime)s %(levelname)s %(module)s: %(message)s',
        datefmt="%H:%M:%S"
    )
    asyncio.run(main())

Version

0.1.1

Environment Details (Optional)

No response

Failure Logs (Optional)

No response

Additional Information (Optional)

No response

@qati qati assigned XaviPeiro and unassigned qati Jul 18, 2024
@XaviPeiro
Copy link
Collaborator

@abhifetch I appreciate you mentioned the file you were executing (just pointing the path will do it).

To identify the contingent problem, will be necessary you to add the specific steps you followed to reproduce the error. This is, the concrete actions that are not common to every single execution or user.

In this case:
1.- You executed python examples/run_example.py; (show what you got).
2.- The next step is this, so what was the input?
image
3.- etc...

@XaviPeiro XaviPeiro added the s-blocked Status: Blocked - waiting on more information or changes label Jul 22, 2024
@abhifetch
Copy link
Author

I took the example from https://github.com/fetchai/ai-engine-sdk-python/blob/master/examples/run_example.py
and edited line 28-30 from:
public_group = next((g for g in function_groups if g.name == "Fetch Verified"), None)
if public_group is None:
raise Exception('Could not find "Public" function group.')

to:

my_group = next(
(g for g in function_groups if g.name == "My Functions"),
None)

to get my functions functions group. I tried doing coin toss example and it is working fine.

  1. I executed the above script mentioned above.
  2. Coin toss example is working fine, but I have another dialogues example which works fine on deltaV. I have given objective as 'i want to find stocks price for multiple companies'.
Screenshot 2024-07-22 at 12 37 04

It is able to find the function but while running, it shows your agent is offline or i am executing the task and not do anything for 100 iterations. I am sharing my agent's code , logs and sdk code in files below.

scripts.zip

@XaviPeiro XaviPeiro removed the s-blocked Status: Blocked - waiting on more information or changes label Jul 22, 2024
@XaviPeiro
Copy link
Collaborator

“talkative” model was used instead of “next-gen”. For the nonce only "next-gen" is working.

@XaviPeiro XaviPeiro reopened this Jul 24, 2024
@XaviPeiro
Copy link
Collaborator

That casuistic requires to be added in the READ.ME and provide a clear solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants