# Simple Agent

**Prerequisites**

* AgentGPT CLI installed (`pip install agentgpt`).
* Valid API key with **agent:write** permissions.

***

#### **1. Agent Design Goal**

Create a **GreetingBot** agent that:

1. Detects user language from input text.
2. Responds with a culturally appropriate greeting.
3. Logs interactions for compliance.

***

#### **2. Code Implementation**

**Step 1: Import SDK & Initialize Client**

```python
from agentgpt import Agent
from agentgpt.utils import detect_language, format_response

class GreetingBot(Agent):
    def __init__(self):
        super().__init__(
            name="GreetingBot_v1",
            description="Multilingual greeting agent",
            compliance_tags=["GDPR"]
        )
        
        # Add approved language list
        self.supported_languages = ["en", "es", "ja"]

    async def on_message(self, message: str) -> dict:
        """Process incoming message"""
        # Detect language
        lang = detect_language(message)
        
        if lang not in self.supported_languages:
            return self._error_response("Language not supported")
            
        return {
            "response": self._generate_greeting(lang),
            "metadata": {
                "detected_language": lang,
                "timestamp": self.current_timestamp()
            }
        }

    def _generate_greeting(self, lang: str) -> str:
        """Language-specific greetings"""
        greetings = {
            "en": "Hello! How can I assist you today?",
            "es": "¡Hola! ¿En qué puedo ayudarle?",
            "ja": "こんにちは!どのようにお手伝いできますか?"
        }
        return format_response(greetings[lang])

    def _error_response(self, reason: str) -> dict:
        """Standard error format"""
        return {
            "error": "GREET_002",
            "message": f"Greeting failed: {reason}",
            "resolution": "Contact support@agent-gpt.io"
        }
```

***

#### **3. Deploy the Agent**

**A. Local Testing**

```bash
# Spin up local test server
agentgpt local --port 8080 --agents GreetingBot
```

**Sample Interaction**

```bash
curl -X POST http://localhost:8080/v1/greeting \
  -H "Authorization: Bearer API_KEY" \
  -d '{"message": "Buenos días"}'
  
# Response
{
  "response": "¡Hola! ¿En qué puedo ayudarle?",
  "metadata": {
    "detected_language": "es",
    "timestamp": "2025-02-08T14:30:22Z"
  }
}
```

**B. Production Deployment**

```python
from agentgpt import DeploymentConfig

# Configure deployment settings  
config = DeploymentConfig(
    environment="prod-eu",
    scaling={
        "min_replicas": 2,
        "max_replicas": 10,
        "target_latency": "100ms"
    },
    compliance={
        "log_retention_days": 30,
        "data_region": "EU"
    }
)

# Deploy to AgentGPT Cloud  
deployment_id = client.deploy(
    agent=GreetingBot(),
    config=config,
    dry_run=False
)
```

***

#### **4. Monitoring & Logging**

Access agent metrics via CLI:

```bash
agentgpt metrics get --agent GreetingBot_v1 --timeframe 1h
```

**Sample Output**

```
Requests: 1.2k | Avg Latency: 47ms | Errors: 0.3%
Languages Detected:
- en: 58% 
- es: 30%
- ja: 12%
```

***

#### **5. Best Practices**

1. **Input Validation**: Always sanitize inputs using `agentgpt.utils.sanitize_input()`
2. **Graceful Degradation**: Implement circuit breakers for external dependencies
3. **Async Operations**: Use `async/await` for I/O-intensive tasks
4. **Version Control**: Tag agents with semantic versions (e.g., GreetingBot\_v1.2.0)

***

#### **6. Customization Options**

1. **Add New Languages**:

```python
self.supported_languages.append("de")
greetings["de"] = "Guten Tag! Wie kann ich Ihnen helfen?"
```

2. **Integrate with CRM**:

```python
from agentgpt.integrations import SalesforceConnector

self.salesforce = SalesforceConnector()
# Add to response metadata:
user_data = self.salesforce.get_user_profile(message.sender_id)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://agent-gpt.gitbook.io/agent-gpt/examples/simple-agent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
