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

[Issue]: Assistant not answering question when providing clear question and context? #3535

Open
windowshopr opened this issue Sep 16, 2024 · 0 comments

Comments

@windowshopr
Copy link

windowshopr commented Sep 16, 2024

Describe the issue

Attempting to create a simple QA RAG chat between the RetrieveUserProxyAgent and AssistantAgent. I will provide my code below, however note that I am using one textbook in .txt format in my "./data/csc" directory for the context, which I won't provide here, however I will provide the retrieved context in its entirety for others to test on their end, just be prepared for a long copy/paste section below. See the code and output:

from autogen import AssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
from autogen.cache import Cache

# Use Ollama's llama3:8b model for the User and Assistant Agents
llm_config = {
    "llama3:8b": {
        "config_list": [
            {
                "model": "llama3:8b",
                "api_key": "NA",
                "api_type": "openai",
                "base_url": "http://localhost:11434/v1",
            },
        ],
        "temperature": 0.01,
        "timeout": 7200,
    }
}

# The task to ask the AssistantAgent to perform
CLIENT_REQUEST = "Ten years ago, what percentage of the average investor's financial assets (bank accounts, registered retirement savings plans, pension, insurance, etc.) were stocks, and what has that percentage grown to today?"
# Desired sentence to reference from context: "Ten years ago, 22% of the average investor’s financial assets (bank accounts, registered retirement savings plans, pension, insurance, etc.) were stocks. Today, this share has grown to 30%."



# The configuration for the RetrieveUserProxyAgent
custom_retrieve_config = {
    "task": "qa",
    "vector_db": "chroma",
    "db_config": {},
    "docs_path": "./data/csc",
    "extra_docs": True,
    "new_docs": True,
    "model": llm_config["llama3:8b"]["config_list"][0]["model"],
    "chunk_token_size": 1024,
    "context_max_tokens": 4096,
    "chunk_mode": "multi_lines",
    "must_break_at_empty_line": True,
    "embedding_model": "all-MiniLM-L6-v2",
    "embedding_function": None,
    "customized_prompt": None,
    "update_context": True,
    "collection_name": "CSCCollection",
    "get_or_create": False,
    "overwrite": False,
    # "custom_token_count_function": len,
    "custom_text_split_function": None,
    # "custom_text_types": None,
    "recursive": True,
    "distance_threshold": -1,
}


# Create a Client UserProxyAgent to interact with the AssistantAgent.
client = RetrieveUserProxyAgent(
    name="Client",
    human_input_mode="ALWAYS",
    is_termination_msg=None,
    retrieve_config=custom_retrieve_config,
    max_consecutive_auto_reply=3,
    code_execution_config=False,
    default_auto_reply=None,
    llm_config=llm_config["llama3:8b"],
    system_message="You are the Client UserProxyAgent asking the Assistant for answers to your questions.",
    description="UserProxyAgent that asks the Assistant for answers to questions.",
)

# Create an AssistantAgent to generate answers for the Client.
assistant = AssistantAgent(
    name="Assistant",
    system_message="You are a helpful AssistantAgent that answers questions asked by the Client.",
    llm_config=llm_config["llama3:8b"],
    is_termination_msg=None,
    human_input_mode="ALWAYS",
    default_auto_reply="TERMINATE",
    max_consecutive_auto_reply=3, # used only when human_input_mode is not ALWAYS
    code_execution_config=False,
    description="AssistantAgent that generates answers to questions asked by the Client.",
)

# Reset the AssistantAgent to clear its memory
def _reset_agent(agent):
    agent.reset()

# START
if __name__ == "__main__":

    _reset_agent(assistant)
    
    with Cache.disk() as cache:

        response = client.initiate_chat(assistant, 
                                        clear_history=False,
                                        silent=False,
                                        cache=cache,
                                        max_turns=None,
                                        message=client.message_generator,
                                        problem=CLIENT_REQUEST,
                                        n_results=3,
                                        )
    
    print(response)

Steps to reproduce

Python 3.11
Windows 10
ollama version is 0.3.10, with llama3:8b in my example
pyautogen==0.3.0

Create a "./data/csc" folder, make a .txt file in it, and copy paste this context:

For example, by the end of 2007, individual Canadians had just over $500 billion in personal
savings deposits at the chartered banks alone (Source: Bloomberg). They had many more billions
of dollars at other financial intermediaries such as trust companies, credit unions and investment
dealers. Canadians also have other substantial assets in the form of securities investments made
either directly or indirectly through investment funds and pension plans, equity in homes and
businesses, cash values of insurance policies, retirement plans, etc.
Over the past ten years, Canadian investors’ holdings of securities have doubled to more than
$600 billion today. Ten years ago, 22% of the average investor’s financial assets (bank accounts,
registered retirement savings plans, pension, insurance, etc.) were stocks. Today, this share has
grown to 30%. Canadians are increasingly turning to the securities industry to ensure their
prosperity and future retirement security.
Foreign investors also are a significant source of investment capital. Historically, Canada has
depended upon large inflows of foreign investment for continued growth. Foreign direct
investment in Canada has tended to concentrate in particular industries: manufacturing,
petroleum and natural gas, and mining and smelting. There are many industries that are largely
Canadian-controlled (e.g., merchandising, finance, agriculture, transportation, construction,
utilities). Some industries also have restrictions with respect to foreign investment.
Canada’s use of foreign investment, while necessary, has its costs. Some Canadian economic
nationalists feel that direct foreign investment implies control. They feel that foreign investment
leads to long-term outflows of interest and dividend payments, negatively affecting our
international balance of payments. They also fear that foreign owners may favour their own
domestic plants, or subsidiaries in other countries over their Canadian subsidiaries in the pursuit
of export markets, research and development efforts, and in plant closings or layoffs during
recessions.
The debate on the appropriate level of foreign investment in Canada will, no doubt, continue.
But over the past 20 years there has been a significant swing in government policy away from
the protection of Canadian businesses. The Canadian Government and the business community
recognize that foreign capital continues to be needed and that foreign investors must be made to
feel that Canada is a safe and attractive country in which to invest.
1•8 CANADIAN SECURITIES COURSE • VOLUME 1
© CSI GLOBAL EDUCATION INC. (2010)
Users of Capital
Based on the simplest categorization, the users of capital are individuals, businesses and
governments. These can be both Canadian and foreign users. The ways in which these groups use
capital are described below.
INDIVIDUALS
Individuals may require capital to finance housing, consumer durables (e.g., automobiles,
appliances) or other types of consumption. They usually obtain it through incurring indebtedness
in the form of personal loans, mortgage loans or charge accounts. Since individuals do not issue
securities to the public and the focus of this text is on securities, individual capital users are not
discussed further.
Just as foreign individuals, businesses or governments can supply capital to Canada, capital
can flow in the other direction. Foreign users (mainly businesses and governments) may access
Canadian capital by borrowing from Canadian banks or by making their securities available to
the Canadian market. Foreign users will want Canadian capital if they feel that they can access
this capital at a less expensive rate than their own currency. Access to foreign securities benefits
Canadian investors, who are thus provided with more choice and an opportunity to further
diversify their investments.
BUSINESSES
Canadian businesses require massive sums of capital to finance day-to-day operations, to renew
and maintain plant and equipment as well as to expand and diversify activities. A substantial part
of these requirements is generated internally (e.g., profits retained in the business), while some is
borrowed from financial intermediaries (principally the chartered banks). The remainder is raised
in securities markets through the issuance of short-term money market paper, medium- and longterm
debt, and preferred and common shares. These instruments are discussed in detail in later
chapters.
THE FEDERAL GOVERNMENT
Governments in Canada are major issuers of securities in public markets, either directly or
through guaranteeing the debt of their Crown corporations.
Each year the Minister of Finance presents the government’s budget to Parliament. The budget
details the government’s estimate of its revenues and expenses, which in turn results in a
projection of a budget surplus or budget deficit.
When revenues fail to meet expenditures and/or when large capital projects are planned, the
federal government must borrow. The government makes use of four main instruments: treasury
bills (T-bills), marketable bonds, Canada Savings Bonds (CSBs) and Canada Premium Bonds
(CPBs). The characteristics of each of these instruments are discussed in detail in the material on
fixed-income products.
PROVINCIAL AND MUNICIPAL GOVERNMENTS
Like the federal government, the provinces issue debt directly themselves and may guarantee
over any period of time. Most stock indexes are value-weighted and are derived by using the total market value (i.e., market capitalization) of all stocks used in the index relative to a base period. The total market value of a stock is found by multiplying its current price by the number of shares outstanding. Each day, the total market value of all stocks included in the series is calculated, and this value is compared to the initial base value to determine the percentage change in the index.
Example: The S&P/TSX Compos ite Index closed at a value of 10,230 on October 6, 2008, and at a
value of 11,248 on October 6, 2009 . The change in the Index translates into a ga in of 9 .95% for the
per iod .
In a value-weighted index, such as the S&P/TSX Composite Index or the S&P 500, companies
with large market capitalizations dominate changes in the value of the index over time. Thus a change in the market capitalization of a large company will have a greater impact on the value of the index than a comparable change in the market capitalization of a smaller company.
A stock average  is the arithmetic average of the current prices of a group of stocks designed to
represent the overall market or some part of it. Most stock averages are price-weighted, which means that movements in the average are tied directly to changes in the prices of the stocks included in the group.
Probably the most widely used stock market average is the Dow Jones Industrial Average (DJIA).
The DJIA includes 30 large, blue-chip stocks that trade on the New York Stock Exchange (NYSE). The DJIA is computed each day by adding up the current prices of the 30 stocks in the index and dividing by a specific divisor developed by Dow Jones & Co. The divisor adjusts the sum of the stock 
prices to reflect more accurately changes in value, for example from stock splits or mergers.
In contrast to a market-weighted stock index, stocks included in an average are composed of
equally weighted items. Within a stock index, each stock has a relative weight based on the stock’s total market capitalization. A stock’s relative weight within an index can change every day, whereas a stock’s weight within an average is always the same.STOCK INDEXE S AND AVERA GESEIGHT • EQUITY SECURITIES: COMMON AND PREFERRED SHARES 8•25
© CSI GLOBAL EDUCATION INC. (2010)Canadian Market Indexes
In Canada, the Toronto Stock Exchange and the TSX Venture Exchange compile and publish
indexes of stock prices for a variety of industry classifications. These indexes, their dividend yields, and the price-earnings ratios based on the S&P/TSX Composite Index can be found in the TSX Monthly Review , the B ank of Canada Review , and in financial newspapers in Canada and
elsewhere.
THE S&P/TSX COMPOSITE INDEX
The Toronto Stock Exchange began its first stock price indexes in 1934. Many changes and revisions have been made to the Index over the years. Figure 8.1 illustrates the growth of the market since 1980.
FIGURE 8.1 YEAR-END CLOSES, S&P/TSX AND S&P/TSX 60 INDEXES
0 2,0004,000 6,000 8,000 10,000 S&P/TSX 60 Index S&P/TSX Compos ite Index S&P/TSX 60 S&P/TSX
300400500600
1980 1985 1990 1995 2000 2005700
12,00014,000800
Source : Bloomberg
The S&P/TSX Composite Index measures changes in the total market capitalization of the
stocks in the Index. A stock’s weight within the Index changes if its price or the number of shares outstanding changes. The Index has a floating 
number of stocks.CANADIAN SECURITIES COURSE • VOLUME 1 8•26
© CSI GLOBAL EDUCATION INC. (2010)To be included in the Index, a stock must meet the following criteria based on price,
capitalization and liquidity:
• Companies must be listed on the Toronto Stock Exchange for at least 12 full calendar
months as of the month end prior to the index stock review meeting;
• A company must have a minimum trade-weighted price of $1.00 over the past quarter as well as a closing price greater than or equal to $1 at the 
previous month-end;
• A company must represent a minimum weight of 0.05% of the Index, after including the
fl oat for that company in the total fl  oat capitalization for the Index;
• T rading volume, value and transactions of a candidate company for the 12 months
14•25
Net return on invested capital,
14•24 to 14•25
Net tangible assets, 14•15 to 14•16Net worth, 12•5New Account Application Form,
3•15, 15•21
New York Stock Exchange (NYSE),
1•14, 1•15
 indexes, 8•29NEX, 1•21, 11•32Nikkei Stock Average (225) Price
Index, 8•30
No-load funds, 18•11 to 18•12
No par value (n.p.v.) shares, 11•18,
11•19
Nominal GDP , 4•11Nominal interest rate, 4•25
Nominal rate of return, 7•14, 7•15,
15•9
Nominee, 3•20Non-Accelerating Infl  ation Rate of
Unemployment (NAIRU), 4•23
Non-callable preferred shares, 8•18Non-competitive tender, 11•14Non-controlling interest, 12•11 to
12•12, 12•17INDEX Ind•13
© CSI GLOBAL EDUCATION INC. (2010)  Non-operating income, 12•14 to
12•15
Non-systematic risk, 15•11Non-trading employees, 3•14Notes to fi  nancial statements,
12•22, 14•9 to 14•10
Notional units, 20•5
O
Odd lot, 8•5Offer, 1•11Offering memorandum, 21•6Offering price:  for mutual fund share or unit,
18•10
 for rights, 10•33Offi ce of the Superintendent of
Financial Institutions (OSFI),
3•5, 20•17
Ombudsman for Banking Services
and Investments (OBSI), 3•12
Open-end funds, 1•10, 2•22. See
also Mutual funds
Open-end trust, 18•8Open interest, 10•18Open market operations, 5•14 to
5•16
Open order, 8•9Operating cash fl  ow ratio, 14•14 to
14•15
Operating costs (amortization
excluded), 14•5 to 14•6
Operating expenses (amortization
included), 12•15, 12•16
Operating income, 12•14 to 12•15Operating performance ratios,
14•12, 14•22 to 14•27
 after-tax return on invested
capital, 14•24 to 14•25
 gross profi  t margin, 14•22
 inventory turnover, 14•25 to
14•27
 net profi  t margin, 14•24
 operating profi  t margin, 14•23
 pre-tax profi  t margin, 14•23
 pre-tax return on invested capital,
14•24
 return on common equity
(ROE), 14•25
Operating profi  t margin ratio,
14•23
Option premium, 10•14Option strategies, 10•18 to 10•26 buying calls to manage risk,
10•21
 buying calls to speculate, 10•19
to 10•21
 buying puts to manage risk, 10•23 to 10•24
 buying puts to speculate, 10•23 cash-secured put writing, 10•24
to 10•25
 covered call writing, 10•21 naked call writing, 10•21
 naked put writing, 10•25 strategies for corporations, 10•25
to 10•26
Options, 1•10, 10•14 to 10•26

Screenshots and logs

Here is the log of the conversation:

Client (to Assistant):

You're a retrieve augmented chatbot. You answer user's questions based on your own knowledge and the
context provided by the user.
If you can't answer the question with or without the current context, you should reply exactly `UPDATE CONTEXT`.
You must give as short an answer as possible.

User's question is: Ten years ago, what percentage of the average investor's financial assets (bank accounts, registered retirement savings plans, pension, insurance, etc.) were stocks, and what has that percentage grown to today?

Context is: For example, by the end of 2007, individual Canadians had just over $500 billion in personal
savings deposits at the chartered banks alone (Source: Bloomberg). They had many more billions
of dollars at other financial intermediaries such as trust companies, credit unions and investment
etc etc etc etc

--------------------------------------------------------------------------------
Replying as Assistant. Provide feedback to Client. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:

>>>>>>>> NO HUMAN INPUT RECEIVED.

>>>>>>>> USING AUTO REPLY...
[autogen.oai.client: 09-16 11:51:48] {349} WARNING - Model llama3:8b is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
Assistant (to Client):

I'm a retrieve augmented chatbot! I can answer your questions based on my knowledge. What's your question?

--------------------------------------------------------------------------------
Replying as Client. Provide feedback to Assistant. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: Answer the question I asked in the original prompt.
Client (to Assistant):

Answer the question I asked in the original prompt.

--------------------------------------------------------------------------------
Replying as Assistant. Provide feedback to Client. Press enter to skip and use auto-reply, or type 'exit' to end the conversation:

>>>>>>>> NO HUMAN INPUT RECEIVED.

>>>>>>>> USING AUTO REPLY...
[autogen.oai.client: 09-16 11:52:28] {349} WARNING - Model llama3:8b is not found. The cost will be 0. In your config_list, add field {"price" : [prompt_price_per_1k, completion_token_price_per_1k]} for customized pricing.
Assistant (to Client):

You originally asked me to be a "helpful AssistantAgent that answers questions asked by the Client." So, I'll do just that!

What's your question? I'm here to help!

So clearly the Assistant is unable to answer the question it was asked in the first prompt, and has no memory of it when asked to answer it a second time.

Additional Information

One thing I noticed is that even when setting the n_results to 3 or even 1, the context length is still long. It makes me wonder if the context being provided to the Assistant is too large to find the question, let alone the answer? I've tried other combinations of "single-line" for the chunk_mode, ranging token sizes and others, still no dice.

I would also like for the assistant to have a "memory" of the responses. For example, even if it didn't "get" the context from the first prompt, it should surely be able to see and review it on the second prompt? It's like each prompt is its own entity, and it doesn't "remember" anything after. So if someone can test on their end to fix the original issue, but then also maybe show proper syntax for remembering and storing a conversation's history? Thanks.

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

1 participant