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

TeachableAgent #278

Merged
merged 66 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
93ee755
Initial commit.
rickyloynd-microsoft Sep 21, 2023
4d2ccf6
Disable LLM response caching.
rickyloynd-microsoft Sep 27, 2023
1c61c73
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 3, 2023
fa033c0
Add teachability option to setup.py
rickyloynd-microsoft Oct 3, 2023
165d5ce
Modify test to use OAI_CONFIG_LIST as suggested in the docs.
rickyloynd-microsoft Oct 3, 2023
295f9e0
Expand unit test.
rickyloynd-microsoft Oct 4, 2023
515f2d9
Complete unit test.
rickyloynd-microsoft Oct 4, 2023
07cc364
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 5, 2023
3443e57
Add filter_dict
rickyloynd-microsoft Oct 6, 2023
dfe47a5
details
rickyloynd-microsoft Oct 6, 2023
c61d69c
AnalysisAgent
rickyloynd-microsoft Oct 7, 2023
748ffcd
details
rickyloynd-microsoft Oct 9, 2023
1e6e889
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 9, 2023
25faf14
More documentation and debug output.
rickyloynd-microsoft Oct 10, 2023
66f4c61
Support retrieval of any number of relevant memos, including zero.
rickyloynd-microsoft Oct 10, 2023
e796832
More robust analysis separator.
rickyloynd-microsoft Oct 11, 2023
b31141f
cleanup
rickyloynd-microsoft Oct 11, 2023
18387a7
teach_config
rickyloynd-microsoft Oct 11, 2023
0f49f0d
refactoring
rickyloynd-microsoft Oct 11, 2023
09fde25
For robustness, allow more flexibility on memo storage and retrieval.
rickyloynd-microsoft Oct 11, 2023
adac582
de-dupe the retrieved memos.
rickyloynd-microsoft Oct 11, 2023
94d8ba0
Simplify AnalysisAgent. The unit tests now pass with gpt-3.5
rickyloynd-microsoft Oct 12, 2023
30503bf
comments
rickyloynd-microsoft Oct 12, 2023
4d2cedd
Add a verbosity level to control analyzer messages.
rickyloynd-microsoft Oct 12, 2023
8a15d0a
refactoring
rickyloynd-microsoft Oct 12, 2023
4806eef
comments
rickyloynd-microsoft Oct 12, 2023
86e9e04
Persist memory on disk.
rickyloynd-microsoft Oct 13, 2023
60bd4c2
cleanup
rickyloynd-microsoft Oct 14, 2023
5f0075b
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 14, 2023
b0ee207
Use markdown to format retrieved memos.
rickyloynd-microsoft Oct 16, 2023
260962d
Use markdown in TextAnalyzerAgent
rickyloynd-microsoft Oct 16, 2023
0da73a3
Add another verbosity level.
rickyloynd-microsoft Oct 16, 2023
15bd56b
clean up logging
rickyloynd-microsoft Oct 16, 2023
cd4cd8f
notebook
rickyloynd-microsoft Oct 17, 2023
ec49ae0
minor edits
rickyloynd-microsoft Oct 17, 2023
d16c368
cleanup
rickyloynd-microsoft Oct 18, 2023
0b24af1
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 18, 2023
2467673
linter fixes
rickyloynd-microsoft Oct 18, 2023
bfc0bc0
Skip tests that fail to import openai
rickyloynd-microsoft Oct 18, 2023
d9c3917
Merge branch 'main' into ricky
thinkall Oct 18, 2023
0974280
Merge branch 'main' into ricky
thinkall Oct 19, 2023
4d90351
Address reviewer feedback.
rickyloynd-microsoft Oct 19, 2023
08c0777
Merge branch 'ricky' of https://github.com/microsoft/autogen into ricky
rickyloynd-microsoft Oct 19, 2023
88d4f95
lint
rickyloynd-microsoft Oct 19, 2023
f1248ed
refactoring
rickyloynd-microsoft Oct 19, 2023
29abbba
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 19, 2023
ea14315
Improve wording
rickyloynd-microsoft Oct 19, 2023
2f99801
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 19, 2023
aef35be
Improve code coverage.
rickyloynd-microsoft Oct 19, 2023
a6eda5d
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 19, 2023
a47e504
lint
rickyloynd-microsoft Oct 19, 2023
a756179
Use llm_config to control caching.
rickyloynd-microsoft Oct 20, 2023
96131a8
lowercase notebook name
rickyloynd-microsoft Oct 20, 2023
08d2000
Sort out the parameters passed through to ConversableAgent, and suppl…
rickyloynd-microsoft Oct 20, 2023
3183c27
lint
rickyloynd-microsoft Oct 20, 2023
da25199
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 20, 2023
c033af8
Allow TextAnalyzerAgent to be given a different llm_config than Teach…
rickyloynd-microsoft Oct 20, 2023
92dc0f6
documentation
rickyloynd-microsoft Oct 20, 2023
848f969
Merge branch 'ricky' of https://github.com/microsoft/autogen into ricky
rickyloynd-microsoft Oct 20, 2023
e13b7cb
Merge branch 'main' into ricky
rickyloynd-microsoft Oct 20, 2023
859acc5
Modifications to run openai workflow.
rickyloynd-microsoft Oct 20, 2023
e13d512
Merge branch 'main' into ricky
sonichi Oct 21, 2023
2745276
Test on just python 3.10.
rickyloynd-microsoft Oct 21, 2023
de17a4e
Merge branch 'ricky' of https://github.com/microsoft/autogen into ricky
rickyloynd-microsoft Oct 21, 2023
ff4a369
Test on python 3.9 instead of 3.10.
rickyloynd-microsoft Oct 21, 2023
f962f45
Remove space from name -> teachableagent
rickyloynd-microsoft Oct 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,6 @@ key_openai.txt
key_aoai.txt
base_aoai.txt
wolfram.txt

# DB on disk for TeachableAgent
tmp/
412 changes: 412 additions & 0 deletions autogen/agentchat/contrib/teachable_agent.py

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions autogen/agentchat/contrib/text_analyzer_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from autogen import oai
from autogen.agentchat.agent import Agent
from autogen.agentchat.assistant_agent import ConversableAgent
from typing import Callable, Dict, Optional, Union, List, Tuple, Any

system_message = """You are an expert in text analysis.
The user will give you TEXT to analyze.
The user will give you analysis INSTRUCTIONS copied twice, at both the beginning and the end.
thinkall marked this conversation as resolved.
Show resolved Hide resolved
You will follow these INSTRUCTIONS in analyzing the TEXT, then give the results of your expert analysis in the format requested."""


class TextAnalyzerAgent(ConversableAgent):
"""Text Analysis agent, a subclass of ConversableAgent designed to answer specific questions about text."""

def __init__(
self,
name: str,
system_message: Optional[str] = system_message,
llm_config: Optional[Union[Dict, bool]] = None,
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
max_consecutive_auto_reply: Optional[int] = None,
human_input_mode: Optional[str] = "NEVER",
code_execution_config: Optional[Union[Dict, bool]] = False,
**kwargs,
):
super().__init__(
name,
system_message,
is_termination_msg,
max_consecutive_auto_reply,
human_input_mode,
code_execution_config=code_execution_config,
llm_config=llm_config,
**kwargs,
)
self.register_reply(Agent, TextAnalyzerAgent._analyze_in_reply)
rickyloynd-microsoft marked this conversation as resolved.
Show resolved Hide resolved
self.use_cache = False # 1 to skip LLM calls made previously by relying on cached responses.

def _analyze_in_reply(
self,
messages: Optional[List[Dict]] = None,
sender: Optional[Agent] = None,
config: Optional[Any] = None,
) -> Tuple[bool, Union[str, Dict, None]]:
"""Analyzes the given text as instructed, and returns the analysis.
Assumes exactly two messages containing the text to analyze and the analysis instructions respectively.
See TeachableAgent.analyze for an example of how to use this method."""
if self.llm_config is False:
return False, None # Return if no LLM was provided.
rickyloynd-microsoft marked this conversation as resolved.
Show resolved Hide resolved
if messages is None:
messages = self._oai_messages[sender] # In case of a direct call.
assert len(messages) == 2

# Delegate to the analysis method.
return True, self.analyze_text(messages[0]["content"], messages[1]["content"])

def analyze_text(self, text_to_analyze, analysis_instructions):
"""Analyzes the given text as instructed, and returns the analysis."""
# Assemble the message.
text_to_analyze = "# TEXT\n" + text_to_analyze + "\n"
analysis_instructions = "# INSTRUCTIONS\n" + analysis_instructions + "\n"
msg_text = "\n".join(
[analysis_instructions, text_to_analyze, analysis_instructions]
) # Repeat the instructions.
messages = self._oai_system_message + [{"role": "user", "content": msg_text}]

# Generate and return the analysis string.
response = oai.ChatCompletion.create(
context=None, messages=messages, use_cache=self.use_cache, **self.llm_config
)
output_text = oai.ChatCompletion.extract_text_or_function_call(response)[0]
return output_text
Loading
Loading