CoolFace
Apppublic

cop91/Customer-Service-Agents-OpenEnv

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

Customer Service OpenEnv

![OpenEnv Compatible](https://huggingface.co/openenv) ![Model](https://groq.com) ![Score]()

A production-grade OpenEnv environment for training AI agents to handle real-world customer support workflows — one of the 4 officially highlighted use cases for the Meta × PyTorch OpenEnv Hackathon.


Business Impact

Customer service AI is one of the highest-ROI AI applications in 2026:

MetricValue
Global AI CS market size (2026)$15.12B
Average cost savings25–30% per year
Ticket auto-resolution rate70–80% of routine tickets
Typical ROI200–500% in first 6 months
Annual loss from poor service (US)$75B

A mid-size company with 500K tickets/year saves $1.6M+ annually if AI handles 40% autonomously. This environment trains agents to achieve exactly that.


Environment Overview

The agent resolves customer support tickets by calling tools across three difficulty levels. Each episode ends when the agent closes or escalates the ticket, with a score from 0.0 to 1.0.

Customer Ticket
      ↓
  Agent calls tools (search_kb, get_order_details, send_reply, issue_refund, ...)
      ↓
  Grader scores: tool use + empathy + resolution + efficiency
      ↓
  Score 0.0 – 1.0 returned

Tasks

TaskDescriptionMax StepsTools Available
easyFAQ / Password reset — search KB and reply5searchkb, askclarification, sendreply, updateticket, close_ticket
mediumMissing order — gather info, check order API, communicate status8+ getorderdetails, issue_refund
hardAngry refund with escalation decision — de-escalate, verify, refund, decide10All tools

Reward Function

Partial progress signals are given at every step — not just on completion:

SignalAmountWhen
Correct tool use+0.02–0.08Per step
KB searched+0.20Easy task
Order verified+0.10–0.20Medium / Hard
Empathetic language+0.10–0.20Hard task
Correct refund amount+0.15Hard task
Ticket resolved+0.15–0.30All tasks
Efficiency bonus+0.15–0.20All tasks
Unnecessary escalation−0.10–0.30Penalty
Rude language−0.07–0.15Penalty
Info without verification−0.10–0.15Penalty

Baseline Results

Running inference.py with llama-3.3-70b-versatile on Groq:

easy     [████████████████████] 1.0000  (3 steps)
medium   [████████████████████] 1.0000  (5 steps)
hard     [████████████████████] 1.0000  (6 steps)

Grand average: 1.0000 / 1.0

Action Space

Each action is a JSON object with two fields:

json
{
  "tool": "<tool_name>",
  "params": { "<param_key>": "<param_value>" }
}
FieldTypeDescription
toolstringName of the tool to call (see Available Tools below)
paramsobjectTool-specific parameters

Example:

json
{"tool": "search_kb", "params": {"query": "password reset"}}
{"tool": "issue_refund", "params": {"amount": 79.99, "reason": "Item lost in transit"}}
{"tool": "close_ticket", "params": {"final_message": "Issue resolved. Thank you!"}}

Observation Space

Each step returns a JSON observation with these fields:

FieldTypeDescription
ticketobjectCurrent ticket state (id, subject, status, customerinfo, notes, refundissued)
conversationarrayFull conversation history (role + content per message)
available_toolsarrayTools the agent can call in this task
step_countintegerNumber of steps taken so far
donebooleanWhether the episode has ended
rewardfloatReward for this step (0.0–1.0; final score when done=true)
tool_resultobjectResult returned by the last tool call
infoobjectExtra info: grader_breakdown (on done), error (on invalid action)

Example observation:

json
{
  "ticket": {"id": "TKT-E001", "subject": "Password Reset", "status": "open", ...},
  "conversation": [{"role": "customer", "content": "I forgot my password"}],
  "available_tools": ["search_kb", "send_reply", "close_ticket"],
  "step_count": 1,
  "done": false,
  "reward": 0.05,
  "tool_result": {"found": true, "answer": "Reset link sent within 30 minutes..."},
  "info": {"partial_reward": 0.05}
}

API

EndpointMethodDescription
/resetPOSTStart a new episode
/stepPOSTTake an action
/stateGETGet full internal state
/healthGETHealth check
/tasksGETList all tasks

Reset

bash
curl -X POST https://YOUR_SPACE.hf.space/reset \
  -H "Content-Type: application/json" \
  -d '{"task_id": "hard", "seed": 42}'

Step

bash
curl -X POST https://YOUR_SPACE.hf.space/step \
  -H "Content-Type: application/json" \
  -d '{"tool": "search_kb", "params": {"query": "password reset"}}'

Available Tools

ToolParamsDescription
search_kbquerySearch FAQ knowledge base (10+ articles)
get_order_detailsorder_idLook up order status, amount, tracking
ask_clarificationquestionAsk customer for missing info
send_replymessage, toneReply to customer (professional/empathetic/apologetic/formal)
update_ticketstatus, noteUpdate ticket status
issue_refundamount, reasonProcess a refund
escalate_to_humanreasonHand off to human agent
close_ticketfinal_messageClose the ticket

Running Locally

bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/customer-service-env
cd customer-service-env
pip install -r requirements.txt

# Start server
uvicorn app.main:app --host 0.0.0.0 --port 7860

# Run baseline agent (in another terminal)
export GROQ_API_KEY_1=gsk_...
python inference.py --task all

# Full evaluation across multiple seeds
python evaluate.py --runs 3

Project Structure

customer-service-env/
├── Dockerfile
├── openenv.yaml          ← OpenEnv manifest
├── inference.py          ← Baseline LLM agent (Groq-powered)
├── evaluate.py           ← Multi-seed evaluation script
├── requirements.txt
└── app/
    ├── main.py           ← FastAPI server (/reset /step /state /health)
    ├── env.py            ← Core environment + reward logic
    ├── models.py         ← Pydantic schemas
    ├── tools.py          ← 8 simulated tools + order database
    ├── tasks/            ← Task definitions (easy / medium / hard)
    ├── graders/          ← Automated graders returning 0.0–1.0
    └── data/
        ├── knowledge_base.json      ← 10 FAQ articles
        └── ticket_templates.json   ← 15 diverse ticket scenarios

License

MIT