Skip to content

Commit 48e09e8

Browse files
committed
fix: add foundation model endpoint
1 parent 7251ed5 commit 48e09e8

File tree

3 files changed

+104
-33
lines changed

3 files changed

+104
-33
lines changed

src/ai/AkamaiAgentCR.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ describe('AkamaiAgentCR', () => {
6060
name: 'test-kb',
6161
description:
6262
'Search the test-kb knowledge base for relevant information. Use this when you need factual information, documentation, or specific details stored in the knowledge base.',
63-
endpoint: undefined,
6463
},
6564
])
6665
})
@@ -111,7 +110,6 @@ describe('AkamaiAgentCR', () => {
111110
type: 'knowledgeBase',
112111
name: 'test-kb',
113112
description: 'Custom description for the knowledge base',
114-
endpoint: undefined,
115113
},
116114
])
117115
})
@@ -154,7 +152,6 @@ describe('AkamaiAgentCR', () => {
154152
name: 'test-kb',
155153
description:
156154
'Search the test-kb knowledge base for relevant information. Use this when you need factual information, documentation, or specific details stored in the knowledge base.',
157-
endpoint: undefined,
158155
},
159156
],
160157
},
@@ -186,7 +183,7 @@ describe('AkamaiAgentCR', () => {
186183
expect(response.spec.tools).toBeUndefined()
187184
})
188185

189-
test('should preserve custom description and endpoint in response', () => {
186+
test('should preserve custom description and apiUrl in response', () => {
190187
const requestWithDetails = {
191188
...mockAgentRequest,
192189
spec: {
@@ -196,7 +193,7 @@ describe('AkamaiAgentCR', () => {
196193
type: 'knowledgeBase',
197194
name: 'test-kb',
198195
description: 'Custom KB description',
199-
endpoint: 'https://api.example.com/kb',
196+
apiUrl: 'https://api.example.com/kb',
200197
},
201198
],
202199
},
@@ -210,7 +207,7 @@ describe('AkamaiAgentCR', () => {
210207
type: 'knowledgeBase',
211208
name: 'test-kb',
212209
description: 'Custom KB description',
213-
endpoint: 'https://api.example.com/kb',
210+
apiUrl: 'https://api.example.com/kb',
214211
},
215212
])
216213
})

src/ai/AkamaiAgentCR.ts

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ export class AkamaiAgentCR {
1818
}
1919
public spec: {
2020
foundationModel: string
21+
foundationModelEndpoint?: string
2122
agentInstructions: string
23+
routes?: Array<{
24+
agent: string
25+
condition: string
26+
apiUrl: string
27+
apiKey?: string
28+
}>
2229
tools?: Array<{
2330
type: string
2431
name: string
2532
description?: string
26-
endpoint?: string
33+
apiUrl?: string
34+
apiKey?: string
2735
}>
2836
}
2937

@@ -42,17 +50,29 @@ export class AkamaiAgentCR {
4250
}
4351
this.spec = {
4452
foundationModel: request.spec.foundationModel,
53+
...(request.spec.foundationModelEndpoint && { foundationModelEndpoint: request.spec.foundationModelEndpoint }),
4554
agentInstructions: request.spec.agentInstructions,
46-
tools: request.spec.tools?.map((tool) => ({
47-
type: tool.type,
48-
name: tool.name,
49-
description:
50-
tool.description ||
51-
(tool.type === 'knowledgeBase'
52-
? `Search the ${tool.name} knowledge base for relevant information. Use this when you need factual information, documentation, or specific details stored in the knowledge base.`
53-
: undefined),
54-
endpoint: tool.endpoint,
55-
})),
55+
...(request.spec.routes && {
56+
routes: request.spec.routes.map((route) => ({
57+
agent: route.agent,
58+
condition: route.condition,
59+
apiUrl: route.apiUrl,
60+
...(route.apiKey && { apiKey: route.apiKey }),
61+
})),
62+
}),
63+
...(request.spec.tools && {
64+
tools: request.spec.tools.map((tool) => ({
65+
type: tool.type,
66+
name: tool.name,
67+
description:
68+
tool.description ||
69+
(tool.type === 'knowledgeBase'
70+
? `Search the ${tool.name} knowledge base for relevant information. Use this when you need factual information, documentation, or specific details stored in the knowledge base.`
71+
: undefined),
72+
...(tool.apiUrl && { apiUrl: tool.apiUrl }),
73+
...(tool.apiKey && { apiKey: tool.apiKey }),
74+
})),
75+
}),
5676
}
5777
}
5878

@@ -79,13 +99,25 @@ export class AkamaiAgentCR {
7999
},
80100
spec: {
81101
foundationModel: this.spec.foundationModel,
102+
...(this.spec.foundationModelEndpoint && { foundationModelEndpoint: this.spec.foundationModelEndpoint }),
82103
agentInstructions: this.spec.agentInstructions,
83-
tools: this.spec.tools?.map((tool) => ({
84-
type: tool.type,
85-
name: tool.name,
86-
...(tool.description && { description: tool.description }),
87-
...(tool.endpoint && { endpoint: tool.endpoint }),
88-
})),
104+
...(this.spec.routes && {
105+
routes: this.spec.routes.map((route) => ({
106+
agent: route.agent,
107+
condition: route.condition,
108+
apiUrl: route.apiUrl,
109+
...(route.apiKey && { apiKey: route.apiKey }),
110+
})),
111+
}),
112+
...(this.spec.tools && {
113+
tools: this.spec.tools.map((tool) => ({
114+
type: tool.type,
115+
name: tool.name,
116+
...(tool.description && { description: tool.description }),
117+
...(tool.apiUrl && { apiUrl: tool.apiUrl }),
118+
...(tool.apiKey && { apiKey: tool.apiKey }),
119+
})),
120+
}),
89121
},
90122
status: {
91123
conditions: [
@@ -103,15 +135,24 @@ export class AkamaiAgentCR {
103135
// Static factory method
104136
static async create(teamId: string, agentName: string, request: AplAgentRequest): Promise<AkamaiAgentCR> {
105137
const aiModels = await getAIModels()
106-
const embeddingModel = aiModels.find(
138+
const foundationModel = aiModels.find(
107139
(model) => model.metadata.name === request.spec.foundationModel && model.spec.modelType === 'foundation',
108140
)
109141

110-
if (!embeddingModel) {
142+
if (!foundationModel) {
111143
throw new K8sResourceNotFound('Foundation model', `Foundation model '${request.spec.foundationModel}' not found`)
112144
}
113145

114-
return new AkamaiAgentCR(teamId, agentName, request)
146+
// Create enriched request with foundationModelEndpoint from the model
147+
const enrichedRequest: AplAgentRequest = {
148+
...request,
149+
spec: {
150+
...request.spec,
151+
foundationModelEndpoint: foundationModel.spec.modelEndpoint,
152+
},
153+
}
154+
155+
return new AkamaiAgentCR(teamId, agentName, enrichedRequest)
115156
}
116157

117158
// Static method to create from existing CR (for transformation)

src/openapi/agent.yaml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,40 @@ AplAgentSpec:
2222
foundationModel:
2323
type: string
2424
description: Name of the foundation model
25-
example: "meta-llama-3"
25+
example: "llama3-1"
26+
foundationModelEndpoint:
27+
type: string
28+
description: HTTP endpoint URL for the foundation model
29+
example: "http://llama-3-1-8b-predictor.team-admin.svc.cluster.local/openai/v1"
2630
agentInstructions:
2731
type: string
2832
description: Custom instructions for the agent
29-
example: "You are a helpful assistant that provides concise answers."
33+
example: "You are a helpful assistant for App Platform for LKE documentation. Give clear answers to the users."
34+
routes:
35+
type: array
36+
description: Routing configuration to other agents based on conditions
37+
items:
38+
type: object
39+
properties:
40+
agent:
41+
type: string
42+
description: Name of the agent to route to
43+
example: "kubernetes-expert"
44+
condition:
45+
type: string
46+
description: Condition that triggers routing to this agent
47+
example: "If the question is about Kubernetes"
48+
apiUrl:
49+
type: string
50+
description: API URL of the target agent
51+
example: "https://my-other-agent.lke496760.akamai-apl.net"
52+
apiKey:
53+
type: string
54+
description: API key for authenticating with the target agent
55+
required:
56+
- agent
57+
- condition
58+
- apiUrl
3059
tools:
3160
type: array
3261
description: Tools available to the agent
@@ -35,19 +64,23 @@ AplAgentSpec:
3564
properties:
3665
type:
3766
type: string
38-
description: Type of the tool
67+
description: Type of the tool (knowledgeBase, mcpServer, subWorkflow, function)
3968
example: "knowledgeBase"
4069
name:
4170
type: string
4271
description: Name of the tool resource
43-
example: "company-docs"
72+
example: "apl-techdocs"
4473
description:
4574
type: string
4675
description: Description of what the tool does
47-
example: "Search the company-docs knowledge base for relevant information"
48-
endpoint:
76+
example: "Search the apl-techdocs knowledge base for relevant information. Use this when you need factual information, documentation, or specific details stored in the knowledge base."
77+
apiUrl:
78+
type: string
79+
description: API URL for the tool (for mcpServer and subWorkflow types)
80+
example: "https://my-mcp.com"
81+
apiKey:
4982
type: string
50-
description: Optional endpoint URL for the tool
83+
description: API key for authenticating with the tool (for mcpServer and subWorkflow types)
5184
required:
5285
- type
5386
- name

0 commit comments

Comments
 (0)