Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/dify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Dify Integration Example

This example demonstrates an A2A agent that integrates with the Dify API.

Check warning on line 3 in examples/dify/README.md

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dify` is not a recognized word. (unrecognized-spelling)

## Features

- Makes HTTP POST requests to the Dify workflow API endpoint

Check warning on line 7 in examples/dify/README.md

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dify` is not a recognized word. (unrecognized-spelling)
- Demonstrates how to wrap an external API in an A2A agent
- Includes both regular and streaming response handling

## Getting started

1. Start the server

```bash
python __main__.py
```

2. Run the test client in another terminal

```bash
python test_client.py
```

## API Details

The agent makes requests to the following Dify endpoint:

Check warning on line 27 in examples/dify/README.md

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dify` is not a recognized word. (unrecognized-spelling)

- URL: `http://192.168.8.41:8080/v1/workflows/run`
- Method: POST
- Headers:
- Authorization: Bearer app-wd1WTcAnHPLqRjTAm4QmswI9
- Content-Type: application/json
- Request Body:
```json
{
"inputs": {},
"response_mode": "blocking",
"user": "test@kingsware.cn"
}
```
1 change: 1 addition & 0 deletions examples/dify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Check failure on line 1 in examples/dify/__init__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`dify` is not a recognized word. (check-file-path)
42 changes: 42 additions & 0 deletions examples/dify/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from a2a.server.apps import A2AStarletteApplication

Check failure on line 1 in examples/dify/__main__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`dify` is not a recognized word. (check-file-path)
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryTaskStore
from a2a.types import (
AgentCapabilities,
AgentCard,
AgentSkill,
)

from agent_executor import DifyAgentExecutor

Check warning on line 10 in examples/dify/__main__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`Dify` is not a recognized word. (unrecognized-spelling)

if __name__ == "__main__":
skill = AgentSkill(
id="dify_api_call",

Check failure on line 14 in examples/dify/__main__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`dify` is not a recognized word. (unrecognized-spelling)
name="Call Dify API",
description="Makes a request to the Dify API endpoint",
tags=["dify", "api", "workflow"],

Check warning on line 17 in examples/dify/__main__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`dify` is not a recognized word. (unrecognized-spelling)
examples=["call dify", "run workflow"],

Check warning on line 18 in examples/dify/__main__.py

View workflow job for this annotation

GitHub Actions / Check Spelling

`dify` is not a recognized word. (unrecognized-spelling)
)

agent_card = AgentCard(
name="Dify Agent",
description="Agent that wraps Dify API",
url="http://localhost:8888/",
version="1.0.0",
defaultInputModes=["text/plain", "application/json"],
defaultOutputModes=["text/plain", "application/json"],
capabilities=AgentCapabilities(streaming=True),
skills=[skill],
)

request_handler = DefaultRequestHandler(
agent_executor=DifyAgentExecutor(),
task_store=InMemoryTaskStore(),
)

server = A2AStarletteApplication(
agent_card=agent_card, http_handler=request_handler
)
import uvicorn

uvicorn.run(server.build(), host="0.0.0.0", port=8888)
Loading