agent-factory: generate agent auto-parse-email-content-and-extrac

This commit is contained in:
2026-04-08 10:41:11 +00:00
parent 58e98ad062
commit 0384b1d569
3 changed files with 50 additions and 26 deletions

View File

@@ -1,8 +1,6 @@
"""
This module defines a LangGraph node function that parses raw email content
and extracts the sender's email address, the email subject, and the email body.
The function uses an LLM to perform the extraction and returns the parsed
information in a structured format.
This module defines a LangGraph node function that parses email content
and extracts the sender's email address, subject, and body using an LLM.
"""
async def process(state: dict) -> dict:
@@ -12,30 +10,21 @@ async def process(state: dict) -> dict:
try:
email_raw = state.get("email_raw", "")
if not email_raw:
return {"error": "Missing 'email_raw' input", "phase": "failed"}
return {"error": "Missing email_raw input", "phase": "failed"}
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."),
HumanMessage(content=email_raw),
SystemMessage(content="You are an assistant that extracts key information from raw email content."),
HumanMessage(content=f"Extract the sender's email, subject, and body from the following email:\n\n{email_raw}")
]
response = await llm.ainvoke(messages)
# Assuming the LLM returns a structured response in the format:
# "Sender: <email>\nSubject: <subject>\nBody: <body>"
try:
lines = response.content.split("\n")
sender_email = next((line.split(": ", 1)[1] for line in lines if line.startswith("Sender:")), "").strip()
email_subject = next((line.split(": ", 1)[1] for line in lines if line.startswith("Subject:")), "").strip()
email_body = next((line.split(": ", 1)[1] for line in lines if line.startswith("Body:")), "").strip()
# Assuming the response is structured as a JSON string with keys: sender_email, email_subject, email_body
parsed_data = response.content.strip()
return {
"sender_email": sender_email,
"email_subject": email_subject,
"email_body": email_body,
"sender_email": parsed_data.get("sender_email", ""),
"email_subject": parsed_data.get("email_subject", ""),
"email_body": parsed_data.get("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:
return {"error": str(exc), "phase": "failed"}

View File

@@ -8,7 +8,7 @@ AUTO_PARSE_EMAIL_CONTENT_AND_EXTRAC_SKILLS = [
AgentSkill(
id="auto_parse_email_content_and_extrac_skill",
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"],
examples=[],
),
@@ -17,7 +17,7 @@ AUTO_PARSE_EMAIL_CONTENT_AND_EXTRAC_SKILLS = [
AGENT_CONFIG = {
"name": "AutoParseEmailContentAndExtrac",
"description": "Extract relevant fields from incoming support email",
"description": "Extract relevant fields from the incoming support email.",
"version": "1.0.0",
"framework": "LangGraph + Starlette",
"capabilities": {

35
catalog-info.yaml Normal file
View 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