# llm\_chat\_with\_json\_output

#### `llm_chat_with_json_output`: Structured JSON Responses

Gets structured JSON responses from the language model according to a specified schema.

```python
def llm_chat_with_json_output(
    agent_name: str, 
    messages: List[Dict[str, Any]], 
    base_url: str = aios_kernel_url,
    llms: List[Dict[str, Any]] = None,
    response_format: Dict[str, Dict] = None
) -> LLMResponse
```

**Parameters:**

* `agent_name`: Identifier for the agent making the request
* `messages`: List of message dictionaries
* `base_url`: API endpoint URL
* `llms`: Optional list of LLM configurations
* `response_format`: JSON schema specifying the required output format

**Returns:**

* `LLMResponse` object containing the structured JSON response

**Example:**

```python
# Extract keywords from a text
response = llm_chat_with_json_output(
    "content_analyzer",
    messages=[
        {"role": "system", "content": "Extract key information from the text."},
        {"role": "user", "content": "AIOS is a new operating system for AI agents."}
    ],
    response_format={
        "type": "json_object",
        "schema": {
            "type": "object",
            "properties": {
                "keywords": {
                    "type": "array",
                    "items": {"type": "string"}
                },
                "summary": {"type": "string"}
            },
            "required": ["keywords", "summary"]
        }
    }
)
print(response["response"]["response_message"])  # JSON string containing keywords and summary
```


---

# 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://docs.aios.foundation/aios-docs/aios-agent-sdk/llm-core-api/llm_chat_with_json_output.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.
