Skip to content

Commit 7ea8a84

Browse files
author
zhang_lu
authored
Merge pull request #180 from lijingcheng2021/react_pro_v1
Refactor: Remove __init__ method and rewrite search functionality for improved modularity
2 parents 8fcb8ea + 27ceebb commit 7ea8a84

File tree

2 files changed

+16
-9
lines changed
  • omagent-core/src/omagent_core/advanced_components/workflow

2 files changed

+16
-9
lines changed

omagent-core/src/omagent_core/advanced_components/workflow/react/agent/wiki_search/wiki_search.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
from omagent_core.engine.worker.base import BaseWorker
22
from omagent_core.utils.registry import registry
33
from omagent_core.utils.logger import logging
4-
from langchain.agents.react.base import DocstoreExplorer
5-
from langchain_community.docstore.wikipedia import Wikipedia
4+
import wikipedia
65
from pydantic import Field
76

7+
class WikipediaSearcher:
8+
"""Simple Wikipedia search implementation that mimics DocstoreExplorer"""
9+
10+
def search(self, query: str) -> str:
11+
"""Search Wikipedia and return the page content"""
12+
try:
13+
page_content = wikipedia.page(query).content
14+
return page_content
15+
except wikipedia.PageError:
16+
return f"Could not find [{query}]. Similar: {wikipedia.search(query)}"
17+
except wikipedia.DisambiguationError:
18+
return f"Could not find [{query}]. Similar: {wikipedia.search(query)}"
19+
820
@registry.register_worker()
921
class WikiSearch(BaseWorker):
1022
"""Wiki Search worker for React workflow"""
1123

12-
def __init__(self, *args, **kwargs):
13-
super().__init__(*args, **kwargs)
14-
self.docstore = DocstoreExplorer(Wikipedia())
24+
wiki_searcher: WikipediaSearcher = Field(default_factory=WikipediaSearcher)
1525

1626
def _run(self, action_output: str, *args, **kwargs):
1727
"""Execute search or lookup based on action output"""
@@ -60,7 +70,7 @@ def _handle_search(self, action_output: str) -> str:
6070
return action_output
6171

6272
try:
63-
result = self.docstore.search(search_term)
73+
result = self.wiki_searcher.search(search_term)
6474
if result:
6575
result_text = result.strip('\n').strip().replace('\n', '')
6676

omagent-core/src/omagent_core/advanced_components/workflow/react_pro/agent/action/action.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class Action(BaseLLMBackend, BaseWorker):
2121
]
2222
)
2323

24-
def __init__(self, *args, **kwargs):
25-
super().__init__(*args, **kwargs)
26-
2724
def _run(self, *args, **kwargs):
2825
"""Process the query using ReAct approach"""
2926
# Get context and other states from STM

0 commit comments

Comments
 (0)