- Agent Server OpenAI 协议:AG-Kit Agent 可暴露兼容 OpenAI 的端点
- Client OpenAI 协议:AG-Kit 可消费来自其他服务的兼容 OpenAI 的应用程序接口
AG-Kit OpenAI 支持
Agent Server OpenAI 协议
AG-Kit Server 在/chat/completions(云环境中为 /v1/aibot/bots/{AgentId}/chat/completions)提供兼容 OpenAI 的端点:
AG-Kit 对 OpenAI 应用程序接口的兼容性支持
/chat/completions(云环境中为 /v1/aibot/bots/{AgentId}/chat/completions)提供兼容 OpenAI 的端点:
from ag_kit_py.server import AgentServiceApp
from ag_kit_py.agents import LangGraphAgent
from langgraph.graph import StateGraph, MessagesState
def create_agent():
# Use the actual chat workflow from examples
from python_sdk.examples.langgraph import build_chat_workflow
workflow = build_chat_workflow()
agent = LangGraphAgent(
name='openai-compatible-agent',
description='You are a helpful assistant.',
graph=workflow
)
return {'agent': agent}
AgentServiceApp().run(create_agent, port=3000)
# OpenAI API available at http://localhost:3000/chat/completions
from ag_kit_py.agents import LangGraphAgent
from langgraph.graph import StateGraph, MessagesState
# Use the actual chat workflow from examples
from python_sdk.examples.langgraph import build_chat_workflow
workflow = build_chat_workflow()
# Note: External API integration would be configured in the LangGraph workflow
agent = LangGraphAgent(
name='openai-client-agent',
description='You are an agent using external OpenAI API.',
graph=workflow
)
import openai
client = openai.OpenAI(
api_key='your-api-key',
base_url='http://localhost:3000'
)
response = client.chat.completions.create(
model='gpt-4', # Model name (can be any string)
messages=[
{'role': 'user', 'content': 'Hello, Agent!'}
]
)
print(response.choices[0].message.content)
functions = [
{
'name': 'get_weather',
'description': 'Get weather information for a location',
'parameters': {
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA'
}
},
'required': ['location']
}
}
]
response = client.chat.completions.create(
model='gpt-4',
messages=[
{'role': 'user', 'content': 'What is the weather in New York?'}
],
functions=functions,
function_call='auto'
)
if response.choices[0].message.function_call:
function_call = response.choices[0].message.function_call
print('Function called:', function_call.name)
此页面对您有帮助吗?