agent-factory: generate agent auto-parse-email-content-and-extrac
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
This module defines a LangGraph node function that parses raw email content
|
This module defines a LangGraph node function that parses email content
|
||||||
and extracts the sender's email address, the email subject, and the email body.
|
and extracts the sender's email address, subject, and body using an LLM.
|
||||||
The function uses an LLM to perform the extraction and returns the parsed
|
|
||||||
information in a structured format.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def process(state: dict) -> dict:
|
async def process(state: dict) -> dict:
|
||||||
@@ -12,30 +10,21 @@ async def process(state: dict) -> dict:
|
|||||||
try:
|
try:
|
||||||
email_raw = state.get("email_raw", "")
|
email_raw = state.get("email_raw", "")
|
||||||
if not email_raw:
|
if not email_raw:
|
||||||
return {"error": "Missing 'email_raw' input", "phase": "failed"}
|
return {"error": "Missing email_raw input", "phase": "failed"}
|
||||||
|
|
||||||
messages = [
|
messages = [
|
||||||
SystemMessage(content="You are an expert in parsing email content. Extract the sender's email address, the subject, and the body from the provided raw email text."),
|
SystemMessage(content="You are an assistant that extracts key information from raw email content."),
|
||||||
HumanMessage(content=email_raw),
|
HumanMessage(content=f"Extract the sender's email, subject, and body from the following email:\n\n{email_raw}")
|
||||||
]
|
]
|
||||||
|
|
||||||
response = await llm.ainvoke(messages)
|
response = await llm.ainvoke(messages)
|
||||||
# Assuming the LLM returns a structured response in the format:
|
# Assuming the response is structured as a JSON string with keys: sender_email, email_subject, email_body
|
||||||
# "Sender: <email>\nSubject: <subject>\nBody: <body>"
|
parsed_data = response.content.strip()
|
||||||
try:
|
return {
|
||||||
lines = response.content.split("\n")
|
"sender_email": parsed_data.get("sender_email", ""),
|
||||||
sender_email = next((line.split(": ", 1)[1] for line in lines if line.startswith("Sender:")), "").strip()
|
"email_subject": parsed_data.get("email_subject", ""),
|
||||||
email_subject = next((line.split(": ", 1)[1] for line in lines if line.startswith("Subject:")), "").strip()
|
"email_body": parsed_data.get("email_body", ""),
|
||||||
email_body = next((line.split(": ", 1)[1] for line in lines if line.startswith("Body:")), "").strip()
|
"phase": "complete"
|
||||||
|
}
|
||||||
return {
|
|
||||||
"sender_email": sender_email,
|
|
||||||
"email_subject": email_subject,
|
|
||||||
"email_body": email_body,
|
|
||||||
"phase": "complete"
|
|
||||||
}
|
|
||||||
except Exception as parse_exc:
|
|
||||||
return {"error": f"Failed to parse LLM response: {str(parse_exc)}", "phase": "failed"}
|
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return {"error": str(exc), "phase": "failed"}
|
return {"error": str(exc), "phase": "failed"}
|
||||||
@@ -8,7 +8,7 @@ AUTO_PARSE_EMAIL_CONTENT_AND_EXTRAC_SKILLS = [
|
|||||||
AgentSkill(
|
AgentSkill(
|
||||||
id="auto_parse_email_content_and_extrac_skill",
|
id="auto_parse_email_content_and_extrac_skill",
|
||||||
name="AutoParseEmailContentAndExtrac",
|
name="AutoParseEmailContentAndExtrac",
|
||||||
description="Parse email content and extract sender, subject, and body",
|
description="Parse email content and extract sender, subject, and body.",
|
||||||
tags=["auto-generated"],
|
tags=["auto-generated"],
|
||||||
examples=[],
|
examples=[],
|
||||||
),
|
),
|
||||||
@@ -17,7 +17,7 @@ AUTO_PARSE_EMAIL_CONTENT_AND_EXTRAC_SKILLS = [
|
|||||||
|
|
||||||
AGENT_CONFIG = {
|
AGENT_CONFIG = {
|
||||||
"name": "AutoParseEmailContentAndExtrac",
|
"name": "AutoParseEmailContentAndExtrac",
|
||||||
"description": "Extract relevant fields from incoming support email",
|
"description": "Extract relevant fields from the incoming support email.",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"framework": "LangGraph + Starlette",
|
"framework": "LangGraph + Starlette",
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
|
|||||||
35
catalog-info.yaml
Normal file
35
catalog-info.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
apiVersion: backstage.io/v1alpha1
|
||||||
|
kind: Component
|
||||||
|
metadata:
|
||||||
|
name: auto-parse-email-content-and-extrac
|
||||||
|
description: "Extract relevant fields from the incoming support email."
|
||||||
|
annotations:
|
||||||
|
backstage.io/kubernetes-label-selector: app=auto-parse-email-content-and-extrac
|
||||||
|
backstage.io/kubernetes-namespace: agents
|
||||||
|
backstage.io/techdocs-ref: dir:.
|
||||||
|
gitea.kyndemo.live/repo-slug: generated-agents/auto-parse-email-content-and-extrac
|
||||||
|
grafana/grafana-instance: default
|
||||||
|
grafana/alert-label-selector: app=auto-parse-email-content-and-extrac
|
||||||
|
grafana/dashboard-selector: uid == 'otel-app-observability-v2'
|
||||||
|
grafana.com/dashboard-url: https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-app=auto-parse-email-content-and-extrac
|
||||||
|
tags:
|
||||||
|
- agent
|
||||||
|
- a2a
|
||||||
|
- auto-generated
|
||||||
|
links:
|
||||||
|
- icon: github
|
||||||
|
title: Source Repository
|
||||||
|
url: https://gitea.kyndemo.live/generated-agents/auto-parse-email-content-and-extrac
|
||||||
|
- icon: code
|
||||||
|
title: CI/CD Pipelines
|
||||||
|
url: https://gitea.kyndemo.live/generated-agents/auto-parse-email-content-and-extrac/actions
|
||||||
|
- icon: dashboard
|
||||||
|
title: Grafana Dashboard
|
||||||
|
url: https://grafana.kyndemo.live/d/otel-app-observability-v2/opentelemetry-application-observability?orgId=1&var-app=auto-parse-email-content-and-extrac
|
||||||
|
spec:
|
||||||
|
type: service
|
||||||
|
lifecycle: experimental
|
||||||
|
owner: group:default/agentic-agents
|
||||||
|
system: agentic-agents
|
||||||
|
dependsOn:
|
||||||
|
- resource:default/cjot-aks
|
||||||
Reference in New Issue
Block a user