Skip to content

Commit ff6e25c

Browse files
authored
Merge pull request #79 from ks6088ts-labs/feature/issue-78_internals
add internals library and slack notifier
2 parents f852dd1 + c02e903 commit ff6e25c

20 files changed

+213
-98
lines changed

.env.template

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ AI_SEARCH_KEY="xxx"
5151
AI_SEARCH_INDEX_NAME="kabuto"
5252

5353
# ---------
54-
# Utilities
54+
# Internals
5555
# ---------
5656

5757
## CSV Loader Settings
@@ -63,3 +63,13 @@ PDF_LOADER_DATA_DIR_PATH="./data"
6363
## OpenTelemetry Settings
6464
OTEL_SERVICE_NAME="template-langgraph"
6565
OTEL_COLLECTOR_ENDPOINT="http://localhost:4317"
66+
67+
## Scraper Settings
68+
SCRAPER_TYPE="mock" # Options: "mock", "httpx", "youtube_transcript"
69+
70+
## Summarizer Settings
71+
SUMMARIZER_TYPE="mock" # Options: "mock", "llm"
72+
73+
## Notifier Settings
74+
NOTIFIER_TYPE="mock" # Options: "mock", "slack"
75+
NOTIFIER_SLACK_WEBHOOK_URL="https://hooks.slack.com/services/xxx"

docs/index.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Pydantic モデルを使用して AI 応答から構造化データを取得す
130130

131131
- **`template_langgraph/llms/`** - LLM API ラッパー(Azure OpenAI など)
132132
- **`template_langgraph/tools/`** - 検索、データ取得用ツール実装
133-
- **`template_langgraph/utilities/`** - ドキュメント読み込みと処理用ヘルパー関数
133+
- **`template_langgraph/internals/`** - 内部ユーティリティとヘルパー関数(CSV/PDF ローダー、Otel ラッパーなど)
134134

135135
## サンプルコードの実行
136136

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Implements the supervisor pattern where one agent coordinates multiple specializ
130130

131131
- **`template_langgraph/llms/`** - LLM API wrappers (Azure OpenAI, etc.)
132132
- **`template_langgraph/tools/`** - Tool implementations for search, data retrieval
133-
- **`template_langgraph/utilities/`** - Helper functions for document loading and processing
133+
- **`template_langgraph/internals/`** - Internal utilities and helper functions (CSV/PDF loaders, Otel wrappers, etc.)
134134

135135
## Running the Examples
136136

scripts/agent_operator.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,12 @@
99
from template_langgraph.agents.image_classifier_agent.models import Results
1010
from template_langgraph.agents.issue_formatter_agent.agent import graph as issue_formatter_agent_graph
1111
from template_langgraph.agents.kabuto_helpdesk_agent.agent import graph as kabuto_helpdesk_agent_graph
12-
from template_langgraph.agents.news_summarizer_agent.agent import MockNotifier, NewsSummarizerAgent
13-
from template_langgraph.agents.news_summarizer_agent.agent import (
14-
graph as news_summarizer_agent_graph,
15-
)
12+
from template_langgraph.agents.news_summarizer_agent.agent import graph as news_summarizer_agent_graph
1613
from template_langgraph.agents.news_summarizer_agent.models import (
1714
AgentInputState,
1815
AgentState,
1916
Article,
2017
)
21-
from template_langgraph.agents.news_summarizer_agent.scrapers import (
22-
BaseScraper,
23-
HttpxScraper,
24-
YouTubeTranscriptScraper,
25-
)
26-
from template_langgraph.agents.news_summarizer_agent.summarizers import (
27-
LlmSummarizer,
28-
)
2918
from template_langgraph.agents.task_decomposer_agent.agent import graph as task_decomposer_agent_graph
3019
from template_langgraph.loggers import get_logger
3120

@@ -56,18 +45,6 @@ def get_agent_graph(name: str):
5645
raise ValueError(f"Unknown agent name: {name}")
5746

5847

59-
def get_scraper(scraper_type: str) -> BaseScraper:
60-
scraper = None
61-
if scraper_type == "Httpx":
62-
scraper = HttpxScraper()
63-
elif scraper_type == "YouTubeTranscript":
64-
scraper = YouTubeTranscriptScraper()
65-
66-
if not scraper:
67-
raise ValueError(f"Unknown scraper type: {scraper_type}")
68-
return scraper
69-
70-
7148
@app.command()
7249
def png(
7350
name: str = typer.Option(
@@ -159,12 +136,6 @@ def news_summarizer_agent(
159136
"-u",
160137
help="Comma-separated list of URLs to summarize",
161138
),
162-
scraper: str = typer.Option(
163-
"Httpx", # YouTubeTranscript
164-
"--scraper",
165-
"-s",
166-
help="Scraper to use for fetching content",
167-
),
168139
verbose: bool = typer.Option(
169140
False,
170141
"--verbose",
@@ -176,11 +147,7 @@ def news_summarizer_agent(
176147
if verbose:
177148
logger.setLevel(logging.DEBUG)
178149

179-
graph = NewsSummarizerAgent(
180-
notifier=MockNotifier(),
181-
scraper=get_scraper(scraper),
182-
summarizer=LlmSummarizer(),
183-
).create_graph()
150+
graph = news_summarizer_agent_graph
184151
for event in graph.stream(
185152
input=AgentState(
186153
input=AgentInputState(

scripts/ai_search_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import typer
44
from dotenv import load_dotenv
55

6+
from template_langgraph.internals.csv_loaders import CsvLoaderWrapper
7+
from template_langgraph.internals.pdf_loaders import PdfLoaderWrapper
68
from template_langgraph.loggers import get_logger
79
from template_langgraph.tools.ai_search_tool import AiSearchClientWrapper
8-
from template_langgraph.utilities.csv_loaders import CsvLoaderWrapper
9-
from template_langgraph.utilities.pdf_loaders import PdfLoaderWrapper
1010

1111
# Initialize the Typer application
1212
app = typer.Typer(

scripts/cosmosdb_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import typer
44
from dotenv import load_dotenv
55

6+
from template_langgraph.internals.csv_loaders import CsvLoaderWrapper
7+
from template_langgraph.internals.pdf_loaders import PdfLoaderWrapper
68
from template_langgraph.loggers import get_logger
79
from template_langgraph.tools.cosmosdb_tool import CosmosdbClientWrapper
8-
from template_langgraph.utilities.csv_loaders import CsvLoaderWrapper
9-
from template_langgraph.utilities.pdf_loaders import PdfLoaderWrapper
1010

1111
# Initialize the Typer application
1212
app = typer.Typer(

scripts/elasticsearch_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import typer
44
from dotenv import load_dotenv
55

6+
from template_langgraph.internals.pdf_loaders import PdfLoaderWrapper
67
from template_langgraph.loggers import get_logger
78
from template_langgraph.tools.elasticsearch_tool import ElasticsearchClientWrapper
8-
from template_langgraph.utilities.pdf_loaders import PdfLoaderWrapper
99

1010
# Initialize the Typer application
1111
app = typer.Typer(

scripts/otel_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import typer
55
from dotenv import load_dotenv
66

7+
from template_langgraph.internals.otel_helpers import OtelWrapper
78
from template_langgraph.loggers import get_logger
8-
from template_langgraph.utilities.otel_helpers import OtelWrapper
99

1010
# Initialize the Typer application
1111
app = typer.Typer(

scripts/qdrant_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from dotenv import load_dotenv
55
from qdrant_client.models import PointStruct
66

7+
from template_langgraph.internals.csv_loaders import CsvLoaderWrapper
78
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper
89
from template_langgraph.loggers import get_logger
910
from template_langgraph.tools.qdrant_tool import QdrantClientWrapper
10-
from template_langgraph.utilities.csv_loaders import CsvLoaderWrapper
1111

1212
# Initialize the Typer application
1313
app = typer.Typer(

template_langgraph/agents/news_summarizer_agent/agent.py

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,27 @@
88
StructuredArticle,
99
SummarizeWebContentState,
1010
)
11-
from template_langgraph.agents.news_summarizer_agent.scrapers import (
12-
BaseScraper,
13-
HttpxScraper,
14-
MockScraper,
15-
)
16-
from template_langgraph.agents.news_summarizer_agent.summarizers import (
17-
BaseSummarizer,
18-
LlmSummarizer,
19-
MockSummarizer,
20-
)
11+
from template_langgraph.internals.notifiers import get_notifier
12+
from template_langgraph.internals.scrapers import get_scraper
13+
from template_langgraph.internals.summarizers import get_summarizer
2114
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper
2215
from template_langgraph.loggers import get_logger
2316

2417
logger = get_logger(__name__)
2518

2619

27-
class MockNotifier:
28-
def notify(self, id: str, body: dict) -> None:
29-
"""Simulate sending a notification to the user."""
30-
logger.info(f"Notification sent for request {id}: {body}")
31-
32-
3320
class NewsSummarizerAgent:
3421
def __init__(
3522
self,
3623
llm=AzureOpenAiWrapper().chat_model,
37-
notifier=MockNotifier(),
38-
scraper: BaseScraper = MockScraper(),
39-
summarizer: BaseSummarizer = MockSummarizer(),
24+
notifier=get_notifier(),
25+
scraper=get_scraper(),
26+
summarizer=get_summarizer(),
4027
):
4128
self.llm = llm
4229
self.notifier = notifier
43-
self.scraper: BaseScraper = scraper
44-
self.summarizer: BaseSummarizer = summarizer
30+
self.scraper = scraper
31+
self.summarizer = summarizer
4532

4633
def create_graph(self):
4734
"""Create the main graph for the agent."""
@@ -127,23 +114,20 @@ def summarize_web_content(self, state: SummarizeWebContentState):
127114
def notify(self, state: AgentState) -> AgentState:
128115
"""Send notifications to the user."""
129116
logger.info(f"Sending notifications with state: {state}")
130-
# Simulate sending notifications
131-
# convert list of articles to a dictionary for notification
132117
summary = {}
133118
for i, article in enumerate(state.articles):
134-
summary[i] = article.model_dump()
119+
summary[i] = {
120+
"url": article.url,
121+
"structured_article": article.structured_article.model_dump(),
122+
}
135123
self.notifier.notify(
136-
id=state.input.id,
137-
body=summary,
124+
text=summary.__str__(),
138125
)
139126
return state
140127

141128

142-
# For testing
143-
# graph = NewsSummarizerAgent().create_graph()
144-
145129
graph = NewsSummarizerAgent(
146-
notifier=MockNotifier(),
147-
scraper=HttpxScraper(),
148-
summarizer=LlmSummarizer(),
130+
notifier=get_notifier(),
131+
scraper=get_scraper(),
132+
summarizer=get_summarizer(),
149133
).create_graph()

0 commit comments

Comments
 (0)