Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 9, 2024
1 parent 82895b7 commit 7f39c97
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 11 deletions.
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions packages/agent/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { addCustomActions } from './actions'
async function _main(runtime: AgentRuntime, message: any, state: any, template: any) {
// compose the text context for message generation
const context = composeContext({
context: state,
template: template,
state,
template,
})

if (runtime.debugMode) {
Expand All @@ -28,9 +28,35 @@ async function _main(runtime: AgentRuntime, message: any, state: any, template:
}

let responseData
const {
senderId,
room_id,
userIds: user_ids,
agentId,
} = message
console.log('message', message)


for (let triesLeft = 3; triesLeft > 0; triesLeft--) {
console.log('message', message)

const response = await runtime.completion({ context, stop: [] })

// log the response
runtime.supabase.from('logs').insert({
body: { message, context, response },
user_id: senderId,
room_id,
user_ids,
agent_id: agentId,
type: 'main_completion'
}).then(({error}) => {
if (error) {
console.error('error', error)
}
}
)

const parsedResponse = parseJSONObjectFromText(response)
if (parsedResponse?.user?.includes(state.agentName)) {
responseData = parsedResponse
Expand Down
4 changes: 1 addition & 3 deletions packages/agent/src/agent/evaluators/introduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ Brief explanation: Kyle mentioned his interest in heavy metal music and playing
const handler = async (message: any, state: any, runtime: any) => {
console.log('handle message', message)
const context = composeContext({
context: {
...state,
},
state,
template,
});

Expand Down
4 changes: 1 addition & 3 deletions packages/agent/src/agent/evaluators/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ const handler = async (_message: any, state: any, runtime: any) => {
// then inject their profile

const context = composeContext({
context: {
...state,
},
state,
template,
})

Expand Down
4 changes: 2 additions & 2 deletions packages/agent/src/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/** compose prompt template from variables and a context template
* replace {{variables}} in {{ }} syntax with values from variables using the key names
*/
export const composeContext = ({ context, template }: any) => {
export const composeContext = ({ state, template }: any) => {
// replace all {{variables}} in contextTemplate with values from variables using the key names
const out = template.replace(/{{\w+}}/g, (match: any) => {
const key = match.replace(/{{|}}/g, "");
return context[key] ?? "";
return state[key] ?? "";
});
return out;
};
2 changes: 1 addition & 1 deletion packages/agent/src/lib/evaluators/reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async function handler(runtime: AgentRuntime, _message: any, state: any) {
.join('\n')

const context = await composeContext({
context: {
state: {
...state,
senderName,
agentName,
Expand Down

0 comments on commit 7f39c97

Please sign in to comment.